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:
@@ -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);
|
||||
@@ -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);
|
||||
};
|
||||
Reference in New Issue
Block a user