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,123 @@
|
||||
import { createAccess } from "../models/Access/operations.js";
|
||||
import { createRole, getAllRoles } from "../models/Role/operations.js";
|
||||
import {
|
||||
createDesignation,
|
||||
getAllDesignations,
|
||||
} from "../models/Designation/operations.js";
|
||||
import {
|
||||
createDepartment,
|
||||
getAllDepartments,
|
||||
} from "../models/Department/operations.js";
|
||||
import { createBranch, getAllBranches } from "../models/Branch/operations.js";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export const createAccessController = async (req, res) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
const { employee, designation, department, branch, role } = req.body;
|
||||
const access = await createAccess({
|
||||
user: employee,
|
||||
designation,
|
||||
department,
|
||||
branch,
|
||||
role,
|
||||
createdBy: user.id,
|
||||
createdOn: dayjs().toISOString(),
|
||||
});
|
||||
res.status(200).json({ result: access });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
export const getAllRolesController = async (req, res) => {
|
||||
try {
|
||||
const roles = await getAllRoles();
|
||||
res.status(200).json({ result: roles });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
export const getAllDesignationsController = async (req, res) => {
|
||||
try {
|
||||
const designations = await getAllDesignations();
|
||||
res.status(200).json({ result: designations });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
export const getAllDepartmentsController = async (req, res) => {
|
||||
try {
|
||||
const departments = await getAllDepartments();
|
||||
res.status(200).json({ result: departments });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
export const getAllBranchesController = async (req, res) => {
|
||||
try {
|
||||
const branches = await getAllBranches();
|
||||
res.status(200).json({ result: branches });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
export const createRoleController = async (req, res) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
const role = await createRole({
|
||||
...req.body,
|
||||
createdBy: user.id,
|
||||
createdOn: dayjs().toISOString(),
|
||||
});
|
||||
res.status(200).json({ result: role });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
export const createDesignationController = async (req, res) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
const designation = await createDesignation({
|
||||
...req.body,
|
||||
createdBy: user.id,
|
||||
createdOn: dayjs().toISOString(),
|
||||
});
|
||||
res.status(200).json({ result: designation });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
export const createDepartmentController = async (req, res) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
const department = await createDepartment({
|
||||
...req.body,
|
||||
createdBy: user.id,
|
||||
createdOn: dayjs().toISOString(),
|
||||
});
|
||||
res.status(200).json({ result: department });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
export const createBranchController = async (req, res) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
const branch = await createBranch({
|
||||
...req.body,
|
||||
createdBy: user.id,
|
||||
createdOn: dayjs().toISOString(),
|
||||
});
|
||||
res.status(200).json({ result: branch });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user