RBAC, jwt implemented in Projects,home and collections routing

This commit is contained in:
2025-09-01 16:52:30 +05:30
parent b8950dc42d
commit 322db1911b
17 changed files with 503 additions and 175 deletions

View File

@@ -1,9 +1,12 @@
import { Request, Response } from "express";
import {
DeleteProject,
GetNodesInProject,
projectCreationService,
projectDatas,
ViewProjectService,
} from "../../shared/services/projectService";
import { AuthenticatedRequest } from "../../shared/utils/token";
export const projectCreationController = async (
req: Request,
@@ -26,7 +29,8 @@ export const projectCreationController = async (
!projectName ||
!userId ||
!apiType ||
!architecture|| !application
!architecture ||
!application
) {
res.status(400).json({
message: "All fields are required",
@@ -37,7 +41,8 @@ export const projectCreationController = async (
organization,
projectName,
useableLanguage,
description,application,
description,
application,
userId,
apiType,
architecture,
@@ -85,18 +90,19 @@ export const projectCreationController = async (
};
export const getProjects = async (
req: Request,
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { organization } = req.body;
if (!organization) {
const { organization, userId } = req.user || {};
if (!organization || !userId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await projectDatas(organization);
const result = await projectDatas({ organization, userId });
console.log("result: ", result);
switch (result.status) {
case "No project found":
@@ -104,7 +110,7 @@ export const getProjects = async (
break;
case "Success":
res.status(200).json({
message: "Project created successfully",
// message: "Projec",
projectDatas: result.data,
});
break;
@@ -121,7 +127,6 @@ export const getProjects = async (
}
};
export const NodesCollectionsBasedOnproject = async (
req: Request,
res: Response
@@ -165,4 +170,100 @@ export const NodesCollectionsBasedOnproject = async (
message: "Unknown error",
});
}
};
};
export const accessAproject = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { organization, userId } = req.user || {};
const { projectId } = req.params;
if (!organization || !userId || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await ViewProjectService({
organization,
userId,
projectId,
});
switch (result.status) {
case "No project found":
res.status(200).json({});
break;
case "Datas not found":
res.status(200).json({ message: "Datas not found" });
break;
case "Success":
res.status(200).json({
projectDatas: result.data,
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
}
};
export const deleteProjectController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { organization, userId } = req.user || {};
const { projectId } = req.params;
if (!organization || !userId || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await DeleteProject({
organization,
userId,
projectId,
});
switch (result.status) {
case "User not found":
res.status(200).json({ message: "User not found" });
break;
case "Project not found":
res.status(200).json({ message: "Project not found" });
break;
case "No access granted to delete this project":
res
.status(200)
.json({ message: "No access granted to delete this project" });
break;
case "Project Delete unsuccessfull":
res.status(200).json({ message: "Project Delete unsuccessfull" });
break;
case "Success":
res.status(200).json({
message: "Project deleted successfully",
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
}
};