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

157 lines
3.7 KiB
TypeScript
Raw Normal View History

import { Request, Response } from "express";
import { Alledges, deleteEdge, edgecreation } from "../../shared/services/edgeService";
export const edgeCreationController = async (
req: Request,
res: Response
): Promise<void> => {
try {
const { organization, projectId, from,to,cardinality } = req.body;
if (!organization || !projectId || !from || !to) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const data = {
organization,
projectId,
from,
to,
cardinality
};
const result = await edgecreation(data);
switch (result.status) {
case "project not found":
res.status(200).json({
message: "project not found",
});
break;
case "From collection not found":
res.status(200).json({
message: "From collection not found",
});
break;
case "To collection not found":
res.status(200).json({
message: "To collection not found",
});
break;
case "Field already exists":
res.status(200).json({
message: "Field already exists",
});
break;
case "Success":
res.status(200).json({
message:"Edge created successfully",
collectionNodeId: result.data,
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
}
};
export const allEdgesController = async (
req: Request,
res: Response
): Promise<void> => {
try {
const { organization, projectId, } = req.body;
if (!organization || !projectId ) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const data = {
organization,
projectId,
};
const result = await Alledges(data);
switch (result.status) {
case "project not found":
res.status(200).json({
message: "project not found",
});
break;
case "edge not found":
res.status(200).json({
message: "edge not found",
});
break;
case "Success":
res.status(200).json({
message:"fetch all Edge datas successfully",
collectionNodeId: result.data,
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
}
};
export const deleteEdgesController = async (
req: Request,
res: Response
): Promise<void> => {
try {
const { organization, projectId, edgeId} = req.body;
if (!organization || !projectId ||!edgeId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const data = {
organization,
projectId,
edgeId
};
const result = await deleteEdge(data);
switch (result.status) {
case "project not found":
res.status(200).json({
message: "project not found",
});
break;
case "edge not found":
res.status(200).json({
message: "edge not found",
});
break;
case "Success":
res.status(200).json({
message:"Edge deleted successfully",
collectionNodeId: result.data,
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
}
};