Files
Schema-Studio/src/api-server/controller/projectController.ts

168 lines
3.9 KiB
TypeScript
Raw Normal View History

2025-08-27 17:48:45 +05:30
import { Request, Response } from "express";
import {
GetNodesInProject,
projectCreationService,
projectDatas,
} from "../../shared/services/projectService";
export const projectCreationController = async (
req: Request,
res: Response
): Promise<void> => {
try {
const {
organization,
useableLanguage,
projectName,
userName,
apiType,
application,
architecture,
description,
} = req.body;
if (
!organization ||
!useableLanguage ||
!projectName ||
!userName ||
!apiType ||
!architecture|| !application
) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const data = {
organization,
projectName,
useableLanguage,
description,application,
userName,
apiType,
architecture,
};
const result = await projectCreationService(data);
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: Request,
res: Response
): Promise<void> => {
try {
const { organization } = req.body;
if (!organization) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await projectDatas(organization);
switch (result.status) {
case "No project found":
res.status(200).json({});
break;
case "Success":
res.status(200).json({
message: "Project created successfully",
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 NodesCollectionsBasedOnproject = async (
req: Request,
res: Response
): Promise<void> => {
try {
const { projectId, organization } = req.params;
if (!organization || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const data = {
organization,
projectId,
};
const result = await GetNodesInProject(data);
switch (result.status) {
case "project not found":
res.status(200).json({
message: "project 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",
});
}
2025-08-27 17:43:27 +05:30
};