View project, update project Data, Usermodel modified Based on the recentlyViewed

This commit is contained in:
2025-05-15 18:53:18 +05:30
parent 46dafd4417
commit bd0c5013a9
7 changed files with 248 additions and 42 deletions

View File

@@ -3,10 +3,14 @@ import {
createProjectController,
GetProjects,
RemoveProject,
updateProjectController,
ViewData,
} from "../controller/project/projectController.ts";
const projectRouter = express.Router();
projectRouter.post("/upsertProject", createProjectController);
projectRouter.get("/Projects/:userId/:organization", GetProjects);
projectRouter.patch("/Project/archive/:projectId", RemoveProject);
projectRouter.patch("/Project/modify", updateProjectController);
projectRouter.get("/Project/view", ViewData);
export default projectRouter;

View File

@@ -3,6 +3,8 @@ import {
createProject,
DeleteProject,
GetAllProjects,
updateProject,
viewProject,
} from "../../../shared/services/project/project-Services.ts";
export const createProjectController = async (
@@ -10,11 +12,13 @@ export const createProjectController = async (
res: Response
): Promise<void> => {
try {
const { projectName, userId, thumbnail, organization } = req.body;
if (!projectName || !userId || !thumbnail || !organization)
const { projectUuid, userId, thumbnail, organization } = req.body;
if (!projectUuid || !userId || !thumbnail || !organization) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await createProject(req.body);
switch (result.status) {
@@ -46,6 +50,7 @@ export const createProjectController = async (
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const GetProjects = async (
@@ -54,10 +59,12 @@ export const GetProjects = async (
): Promise<void> => {
try {
const { userId, organization } = req.params;
if (!userId || !organization)
if (!userId || !organization) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await GetAllProjects({ userId, organization });
switch (result?.status) {
case "User not found":
@@ -81,6 +88,7 @@ export const GetProjects = async (
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const RemoveProject = async (
@@ -90,10 +98,12 @@ export const RemoveProject = async (
try {
const { projectId } = req.params;
const { organization, userId } = req.body;
if (!projectId || !organization || !userId)
if (!projectId || !organization || !userId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await DeleteProject({ projectId, organization, userId });
switch (result?.status) {
case "Project not found":
@@ -121,5 +131,103 @@ export const RemoveProject = async (
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const updateProjectController = async (
req: Request,
res: Response
): Promise<void> => {
try {
const { projectId, organization, projectName, thumbnail, userId } =
req.body;
if (!userId || !organization || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await updateProject({
projectId,
organization,
userId,
projectName,
thumbnail,
});
switch (result?.status) {
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Success":
res.status(200).json({
message: "Project updated Successfully",
projectData: result.data,
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const ViewData = async (req: Request, res: Response): Promise<void> => {
try {
const { projectId, organization, userId } = req.query as {
organization: string;
projectId: string;
userId: string;
};
if (!userId || !organization || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await viewProject({
projectId,
organization,
userId,
});
switch (result?.status) {
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Success":
res.status(200).json({
projectData: result.data,
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};

View File

@@ -9,8 +9,7 @@ export const GetTrashList = async (
res: Response
): Promise<void> => {
try {
const { organization } = req.query as { organization?: string };
console.log("organization: ", organization);
const { organization } = req.query as { organization: string };
if (!organization) {
res.status(400).json({
message: "All fields are required",
@@ -53,8 +52,8 @@ export const RestoreTrash = async (
): Promise<void> => {
try {
const { organization, projectId } = req.query as {
organization?: string;
projectId?: string;
organization: string;
projectId: string;
};
console.log("organization: ", organization);
if (!organization || !projectId) {