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