reinitializing codebase and resuming development
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { createUser, getUserByQuery } from "../models/User/operations.js";
|
||||
import { aggregateAccess } from "../models/Access/operations.js";
|
||||
import bcrypt from "bcrypt";
|
||||
import dayjs from "dayjs";
|
||||
import {
|
||||
@@ -6,6 +7,7 @@ import {
|
||||
getRefreshToken,
|
||||
getEncryptedPayload,
|
||||
} from "../middlewares/jwt.middleware.js";
|
||||
import { ObjectId } from "mongodb";
|
||||
|
||||
export const createUserController = async (req, res, next) => {
|
||||
try {
|
||||
@@ -80,3 +82,66 @@ export const renewAccessTokenController = async (req, res, next) => {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getAccessibleModulesController = async (req, res, next) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
|
||||
const pipeline = [
|
||||
{
|
||||
$match: {
|
||||
user: ObjectId.createFromHexString(user.id),
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "roles",
|
||||
localField: "role",
|
||||
foreignField: "_id",
|
||||
as: "role",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$role",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "departments",
|
||||
localField: "department",
|
||||
foreignField: "_id",
|
||||
as: "department",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$department",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "designations",
|
||||
localField: "designation",
|
||||
foreignField: "_id",
|
||||
as: "designation",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$designation",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const accessibleModules = await aggregateAccess(pipeline)
|
||||
|
||||
res.status(200).json({ result: accessibleModules[0] });
|
||||
} catch (error) {
|
||||
console.log("getAccessibleModulesController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user