Project create APi and collection create API completed
This commit is contained in:
120
src/api-server/controller/projectController.ts
Normal file
120
src/api-server/controller/projectController.ts
Normal file
@@ -0,0 +1,120 @@
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
projectCreationService,
|
||||
projectDatas,
|
||||
} from "../../shared/services/projectService";
|
||||
|
||||
export const projectCreationController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const {
|
||||
organization,
|
||||
useableLanguage,
|
||||
projectName,
|
||||
userName,
|
||||
apiType,
|
||||
architecture,
|
||||
description,
|
||||
} = req.body;
|
||||
if (
|
||||
!organization ||
|
||||
!useableLanguage ||
|
||||
!projectName ||
|
||||
!userName ||
|
||||
!apiType ||
|
||||
!architecture
|
||||
) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectName,
|
||||
useableLanguage,
|
||||
description,
|
||||
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",
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user