346 lines
8.5 KiB
TypeScript
346 lines
8.5 KiB
TypeScript
import { Request, Response } from "express";
|
|
import {
|
|
DeleteProject,
|
|
GetNodesInProject,
|
|
projectCreationService,
|
|
projectDatas,
|
|
projectModification,
|
|
ViewProjectService,
|
|
} from "../../shared/services/projectService";
|
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
|
|
|
export const projectCreationController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const {
|
|
language,
|
|
projectName,
|
|
apiProtocol,
|
|
application,
|
|
architecture,
|
|
description,
|
|
} = req.body;
|
|
if (
|
|
!organization ||
|
|
!language ||
|
|
!projectName ||
|
|
!userId ||
|
|
!apiProtocol ||
|
|
!architecture ||
|
|
!application
|
|
) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const data = {
|
|
organization,
|
|
projectName,
|
|
language,
|
|
description,
|
|
application,
|
|
userId,
|
|
apiProtocol,
|
|
architecture,
|
|
};
|
|
const result = await projectCreationService(data);
|
|
console.log("result:projectcreate ", result);
|
|
|
|
switch (result.status) {
|
|
case "Project Already Exists":
|
|
res.status(403).json({
|
|
message: "Project Already Exists",
|
|
});
|
|
break;
|
|
case "Already MVC architecture assigned to this projectId":
|
|
res.status(403).json({
|
|
message: "Already MVC architecture assigned to this projectId",
|
|
});
|
|
break;
|
|
case "Project creation unsuccessfull":
|
|
res.status(200).json({
|
|
message: "Project creation unsuccessfull",
|
|
});
|
|
break;
|
|
case "Success":
|
|
res.status(200).json({
|
|
message: "Project created successfully",
|
|
projectId: result.data,
|
|
});
|
|
break;
|
|
case "New architecture":
|
|
res.status(200).json({
|
|
message: "New architecture",
|
|
});
|
|
break;
|
|
default:
|
|
res.status(500).json({
|
|
message: "Internal server error",
|
|
});
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: "Unknown error",
|
|
});
|
|
}
|
|
};
|
|
|
|
export const getProjects = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { skip, limit } = req.params;
|
|
if (!organization || !userId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const skipdata = parseInt(skip);
|
|
const limitdata = parseInt(limit);
|
|
const result = await projectDatas({
|
|
organization,
|
|
userId,
|
|
skipdata,
|
|
limitdata,
|
|
});
|
|
|
|
switch (result.status) {
|
|
case "No project found":
|
|
res.status(404).json({});
|
|
break;
|
|
case "Success":
|
|
res.status(200).json({ data: result.data });
|
|
break;
|
|
default:
|
|
res.status(500).json({
|
|
message: "Internal server error",
|
|
});
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: "Unknown error",
|
|
});
|
|
}
|
|
};
|
|
|
|
export const NodesCollectionsBasedOnproject = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { projectId } = req.params;
|
|
if (!organization || !projectId || !userId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const data = {
|
|
organization,
|
|
projectId,
|
|
userId,
|
|
};
|
|
const result = await GetNodesInProject(data);
|
|
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 "No collection Nodes present":
|
|
res.status(200).json({
|
|
message: "No collection Nodes present",
|
|
Collections: result.data,
|
|
});
|
|
break;
|
|
case "Success":
|
|
res.status(200).json(result.data);
|
|
break;
|
|
default:
|
|
res.status(500).json({
|
|
message: "Internal server error",
|
|
});
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
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(404).json({ message: "User not found" });
|
|
break;
|
|
case "Project not found":
|
|
res.status(404).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",
|
|
});
|
|
}
|
|
};
|
|
|
|
export const updateProjectController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const {
|
|
projectId,
|
|
projectName,
|
|
application,
|
|
description,
|
|
language,
|
|
architecture,
|
|
} = req.body;
|
|
if (!organization || !userId || !projectId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const result = await projectModification({
|
|
projectId,
|
|
organization,
|
|
userId,
|
|
projectName,
|
|
application,
|
|
description,
|
|
language,
|
|
architecture,
|
|
});
|
|
|
|
switch (result.status) {
|
|
case "User not found":
|
|
res.status(404).json({ message: "User not found" });
|
|
break;
|
|
case "Project not found":
|
|
res.status(404).json({ message: "Project not found" });
|
|
break;
|
|
case "No access granted to delete this project":
|
|
res
|
|
.status(200)
|
|
.json({ message: "No access granted to update this project" });
|
|
break;
|
|
case "Project update unsuccessfull":
|
|
res.status(200).json({ message: "Project update unsuccessfull" });
|
|
break;
|
|
case "Success":
|
|
res.status(200).json({
|
|
message: "Project updated successfully",
|
|
});
|
|
break;
|
|
default:
|
|
res.status(500).json({
|
|
message: "Internal server error",
|
|
});
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: "Unknown error",
|
|
});
|
|
}
|
|
};
|