178 lines
4.5 KiB
TypeScript
178 lines
4.5 KiB
TypeScript
import { Request, Response } from "express";
|
|
import {
|
|
Alledges,
|
|
deleteEdge,
|
|
edgecreation,
|
|
} from "../../shared/services/edgeService";
|
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
|
export const edgeCreationController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { projectId, from, to, cardinality } = req.body;
|
|
if (!organization || !projectId || !from || !to || !userId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const data = {
|
|
organization,
|
|
projectId,
|
|
from,
|
|
to,
|
|
cardinality,
|
|
userId,
|
|
};
|
|
const result = await edgecreation(data);
|
|
|
|
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 "From collection not found":
|
|
res.status(404).json({
|
|
message: "From collection not found",
|
|
});
|
|
break;
|
|
case "To collection not found":
|
|
res.status(404).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: 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 Alledges(data);
|
|
|
|
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 "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: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { projectId, edgeId } = req.params;
|
|
if (!organization || !projectId || !edgeId || !userId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const data = {
|
|
organization,
|
|
projectId,
|
|
edgeId,
|
|
userId,
|
|
};
|
|
const result = await deleteEdge(data);
|
|
|
|
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 "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",
|
|
});
|
|
}
|
|
};
|