Initialized Project with default middlewares and helpers, connected to Atlas Instance and created Swagger Setup. Created necessary DB models and authentication-authorization logic

This commit is contained in:
Shibi Chakkaravarthy
2026-04-15 02:28:35 +05:30
commit 864e5fae65
71 changed files with 8184 additions and 0 deletions
BIN
View File
Binary file not shown.
+41
View File
@@ -0,0 +1,41 @@
import { model, Schema, Types } from "mongoose";
import user from "../../documentation/user";
const schema = new Schema({
user: {
type: Types.ObjectId,
required: true,
ref: "user",
},
designation: {
type: Types.ObjectId,
required: true,
ref: "designation",
},
department: {
type: Types.ObjectId,
required: true,
ref: "department",
},
role: {
type: Types.ObjectId,
required: true,
ref: "role",
},
branch: {
type: [Types.ObjectId],
required: true,
ref: "branch",
},
createdBy: {
type: Types.ObjectId,
required: true,
ref: "user",
},
createdOn: {
type: Date,
required: true,
},
});
export default model("access", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createAccess = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getAccessById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getAccessByQuery = async (query) => {
return await Model.findOne(query);
};
// Read (Get all)
export const getAllAccesss = async () => {
return await Model.find();
};
// Update
export const updateAccess = async (id, data, options) => {
return await Model.findByIdAndUpdate(id, data, { ...options, new: true });
};
// Aggregate
export const aggregateAccess = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("activity", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createActivity = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getActivityById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getActivityByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllActivitys = async () => {
return await Model.find();
};
// Update
export const updateActivity = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateActivity = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("assignment", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createAssignment = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getAssignmentById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getAssignmentByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllAssignments = async () => {
return await Model.find();
};
// Update
export const updateAssignment = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateAssignment = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+10
View File
@@ -0,0 +1,10 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({
createdOn: {
type: Date,
required: true
}
});
export default model("branch", schema);
+55
View File
@@ -0,0 +1,55 @@
import { model, Schema, Types } from "mongoose";
const coordinatesSchema = new Schema({
latitude: {
type: Number,
required: true,
},
longitude: {
type: Number,
required: true,
},
});
const schema = new Schema({
name: {
type: String,
required: true,
},
address: {
type: String,
required: true,
},
city: {
type: String,
required: true,
},
state: {
type: String,
required: true,
},
pincode: {
type: String,
required: true,
},
createdBy: {
type: Types.ObjectId,
required: true,
ref: "user",
},
createdOn: {
type: Date,
required: true,
},
coordinates: {
type: coordinatesSchema,
required: true,
},
type: {
type: String,
required: true,
enum: ["HQ", "Branch", "Warehouse", "BackOffice"],
},
});
export default model("branch", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createBranch = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getBranchById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getBranchByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllBranches = async () => {
return await Model.find();
};
// Update
export const updateBranch = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateBranch = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+19
View File
@@ -0,0 +1,19 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({
name: {
type: String,
required: true,
},
createdBy: {
type: Types.ObjectId,
required: true,
ref: "user",
},
createdOn: {
type: Date,
required: true,
},
});
export default model("department", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createDepartment = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getDepartmentById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getDepartmentByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllDepartments = async () => {
return await Model.find();
};
// Update
export const updateDepartment = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateDepartment = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+19
View File
@@ -0,0 +1,19 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({
name: {
type: String,
required: true,
},
createdBy: {
type: Types.ObjectId,
required: true,
ref: "user",
},
createdOn: {
type: Date,
required: true,
},
});
export default model("designation", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createDesignation = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getDesignationById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getDesignationByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllDesignations = async () => {
return await Model.find();
};
// Update
export const updateDesignation = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateDesignation = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("expense", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createExpense = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getExpenseById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getExpenseByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllExpenses = async () => {
return await Model.find();
};
// Update
export const updateExpense = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateExpense = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("inventory", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createInventory = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getInventoryById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getInventoryByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllInventorys = async () => {
return await Model.find();
};
// Update
export const updateInventory = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateInventory = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("inventorylog", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createInventoryLog = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getInventoryLogById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getInventoryLogByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllInventoryLogs = async () => {
return await Model.find();
};
// Update
export const updateInventoryLog = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateInventoryLog = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("invoice", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createInvoice = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getInvoiceById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getInvoiceByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllInvoices = async () => {
return await Model.find();
};
// Update
export const updateInvoice = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateInvoice = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("location", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createLocation = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getLocationById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getLocationByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllLocations = async () => {
return await Model.find();
};
// Update
export const updateLocation = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateLocation = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("partner", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createPartner = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getPartnerById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getPartnerByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllPartners = async () => {
return await Model.find();
};
// Update
export const updatePartner = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregatePartner = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+48
View File
@@ -0,0 +1,48 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({
sku: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
buyingPrice: {
type: Number,
required: true,
},
sellingPrice: {
type: Number,
required: true,
},
gst: {
type: Number,
required: true,
},
stock: {
type: Number,
required: true,
},
createdOn: {
type: Date,
required: true,
},
createdBy: {
type: Types.ObjectId,
required: true,
ref: "user",
},
vendors: {
type: [Types.ObjectId],
required: true,
ref: "vendor",
},
});
export default model("product", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createProduct = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getProductById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getProductByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllProducts = async () => {
return await Model.find();
};
// Update
export const updateProduct = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateProduct = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+34
View File
@@ -0,0 +1,34 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({
mobile: {
type: String,
required: true,
},
address: {
type: String,
required: true,
},
city: {
type: String,
required: true,
},
state: {
type: String,
required: true,
},
pincode: {
type: String,
required: true,
},
isActive: {
type: Boolean,
default: true,
},
user: {
type: Types.ObjectId,
required: true,
},
});
export default model("profile", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createProfile = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getProfileById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getProfileByQuery = async (query) => {
return await Model.findOne(query);
};
// Read (Get all)
export const getAllProfiles = async () => {
return await Model.find();
};
// Update
export const updateProfile = async (id, data, options) => {
return await Model.findByIdAndUpdate(id, data, options);
};
// Aggregate
export const aggregateProfile = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+63
View File
@@ -0,0 +1,63 @@
import { model, Schema, Types } from "mongoose";
const moduleSchema = new Schema({
module: {
type: String,
required: true,
enum: [
"branch",
"role",
"designation",
"department",
"user",
"profile",
"access",
"team",
"task",
"target",
"salary",
"vendor",
"expense",
"product",
"invoice",
"partner",
"activity",
"location",
"assignment",
"inventory",
"inventoryLog",
],
},
permission: {
type: String,
required: true,
enum: ["read", "write", "authorize", "delete"],
},
});
const schema = new Schema({
name: {
type: String,
required: true,
},
modules: {
type: [moduleSchema],
required: true,
},
keys: {
type: [String],
required: true,
enum: ["accounts", "admin", "sales", "field", "hr", "logistics"],
},
createdBy: {
type: Types.ObjectId,
required: true,
ref: "user",
},
createdOn: {
type: Date,
required: true,
},
});
export default model("role", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createRole = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getRoleById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getRoleByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllRoles = async () => {
return await Model.find();
};
// Update
export const updateRole = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateRole = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("salary", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createSalary = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getSalaryById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getSalaryByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllSalarys = async () => {
return await Model.find();
};
// Update
export const updateSalary = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateSalary = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("target", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createTarget = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getTargetById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getTargetByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllTargets = async () => {
return await Model.find();
};
// Update
export const updateTarget = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateTarget = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("task", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createTask = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getTaskById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getTaskByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllTasks = async () => {
return await Model.find();
};
// Update
export const updateTask = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateTask = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("team", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createTeam = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getTeamById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getTeamByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllTeams = async () => {
return await Model.find();
};
// Update
export const updateTeam = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateTeam = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+30
View File
@@ -0,0 +1,30 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({
name: {
type: String,
required: true,
},
id: {
type: String,
required: true,
},
hash: {
type: String,
required: true,
},
refreshToken: {
type: String,
required: true,
},
isFirstTime: {
type: Boolean,
default: true,
},
createdOn: {
type: Date,
required: true,
},
});
export default model("user", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createUser = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getUserById = async (id) => {
return await Model.findById(id);
};
//Read (Get by query)
export const getUserByQuery = async (query) => {
return await Model.findOne(query);
};
// Read (Get all)
export const getAllUsers = async () => {
return await Model.find();
};
// Update
export const updateUser = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateUser = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+5
View File
@@ -0,0 +1,5 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
export default model("vendor", schema);
+31
View File
@@ -0,0 +1,31 @@
import Model from "./model.js";
// Create
export const createVendor = async (data) => {
return await Model.create(data);
};
// Read (Get by ID)
export const getVendorById = async (id) => {
return await Model.findById(id);
};
// Read (Get by Query)
export const getVendorByQuery = async (query) => {
return await Model.findOne(query);
}
// Read (Get all)
export const getAllVendors = async () => {
return await Model.find();
};
// Update
export const updateVendor = async (id, data) => {
return await Model.findByIdAndUpdate(id, data, { new: true });
};
// Aggregate
export const aggregateVendor = async (pipeline) => {
return await Model.aggregate(pipeline);
};
+21
View File
@@ -0,0 +1,21 @@
export { default as User } from "./User/model";
export { default as Profile } from "./Profile/model";
export { default as Access } from "./Access/model";
export { default as Team } from "./Team/model";
export { default as Task } from "./Task/model";
export { default as Target } from "./Target/model";
export { default as Branch } from "./Branch/model";
export { default as Salary } from "./Salary/model";
export { default as Vendor } from "./Vendor/model";
export { default as Expense } from "./Expense/model";
export { default as Product } from "./Product/model";
export { default as Invoice } from "./Invoice/model";
export { default as Partner } from "./Partner/model";
export { default as Activity } from "./Activity/model";
export { default as Location } from "./Location/model";
export { default as Assignment } from "./Assignment/model";
export { default as Department } from "./Department/model";
export { default as Designation } from "./Designation/model";
export { default as Inventory } from "./Inventory/model";
export { default as InventoryLog } from "./InventoryLog/model";
export { default as Role } from "./Role/model";