From 477e39f6dcf3e7d9f049ec157534a0142f209e93 Mon Sep 17 00:00:00 2001 From: nivetha Date: Wed, 27 Aug 2025 17:48:45 +0530 Subject: [PATCH] First commit --- src/api-server/app.ts | 40 +- .../controller/collectionNodeController.ts | 918 +++++++------- src/api-server/controller/edgeController.ts | 312 ++--- .../controller/fileModelController.ts | 190 +-- .../controller/projectController.ts | 334 ++--- src/api-server/main.ts | 10 +- src/api-server/routes/collectionRoutes.ts | 116 +- src/api-server/routes/edgeRoutes.ts | 16 +- src/api-server/routes/projectRoutes.ts | 24 +- src/shared/connection/connection.ts | 100 +- src/shared/model/collectionModel.ts | 144 +-- src/shared/model/edgeModel.ts | 58 +- src/shared/model/mvcModel.ts | 76 +- src/shared/model/projectmodel.ts | 86 +- src/shared/services/collectionService.ts | 1118 ++++++++--------- src/shared/services/edgeService.ts | 584 ++++----- src/shared/services/projectService.ts | 370 +++--- 17 files changed, 2248 insertions(+), 2248 deletions(-) diff --git a/src/api-server/app.ts b/src/api-server/app.ts index d75d459..8b6522c 100644 --- a/src/api-server/app.ts +++ b/src/api-server/app.ts @@ -1,20 +1,20 @@ -import express from "express"; -import cors from "cors"; -import dotenv from "dotenv"; -import projectRoutes from "./routes/projectRoutes"; -import collectionNodeRoutes from "./routes/collectionRoutes"; -import edgeRoutes from "./routes/edgeRoutes"; -dotenv.config({ quiet: true }); - -const app = express(); -app.use(cors()); -app.use(express.json({ limit: "50mb" })); -app.use( - express.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 }) -); - -app.use("/api/v1", projectRoutes); -app.use("/api/v1", collectionNodeRoutes); -app.use("/api/v1", edgeRoutes); - -export default app; +import express from "express"; +import cors from "cors"; +import dotenv from "dotenv"; +import projectRoutes from "./routes/projectRoutes"; +import collectionNodeRoutes from "./routes/collectionRoutes"; +import edgeRoutes from "./routes/edgeRoutes"; +dotenv.config({ quiet: true }); + +const app = express(); +app.use(cors()); +app.use(express.json({ limit: "50mb" })); +app.use( + express.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 }) +); + +app.use("/api/v1", projectRoutes); +app.use("/api/v1", collectionNodeRoutes); +app.use("/api/v1", edgeRoutes); + +export default app; diff --git a/src/api-server/controller/collectionNodeController.ts b/src/api-server/controller/collectionNodeController.ts index fa6d193..60938f8 100644 --- a/src/api-server/controller/collectionNodeController.ts +++ b/src/api-server/controller/collectionNodeController.ts @@ -1,459 +1,459 @@ -import { Request, Response } from "express"; -import { - addAttributes, - DelAttributes, - delCollection, - DuplicateCollection, - GetcollectionNode, - GetNodesInProject, - Nodecreation, - SetCollectionName, - UpdateAttributes, -} from "../../shared/services/collectionService"; - -export const NodeCreationController = async ( - req: Request, - res: Response -): Promise => { - try { - const { organization, projectId, position } = req.body; - if (!organization || !projectId || !position) { - res.status(400).json({ - message: "All fields are required", - }); - return; - } - const data = { - organization, - projectId, - position, - }; - const result = await Nodecreation(data); - - switch (result.status) { - case "project not found": - res.status(200).json({ - message: "project not found", - }); - break; - case "Collection node creation unsuccessfull": - res.status(200).json({ - message: "Collection node creation unsuccessfull", - }); - break; - case "Success": - res.status(200).json({ - message: "Node 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 SetCollectionNameController = async ( - req: Request, - res: Response -): Promise => { - try { - const { - organization, - projectId, - collectionNodeId, - collectionName, - position, - } = req.body; - if (!organization || !projectId || !collectionName || !collectionNodeId) { - res.status(400).json({ - message: "All fields are required", - }); - return; - } - const data = { - organization, - projectId, - collectionNodeId, - collectionName, - position, - }; - const result = await SetCollectionName(data); - - switch (result.status) { - case "project not found": - res.status(200).json({ - message: "project not found", - }); - break; - case "Collection not found": - res.status(200).json({ - message: "Collection not found", - }); - break; - case "Success": - res.status(200).json({ - message: "collection name updated", - }); - break; - default: - res.status(500).json({ - message: "Internal server error", - }); - break; - } - } catch (error) { - res.status(500).json({ - message: "Unknown error", - }); - } -}; -export const CollectionDatas = async ( - req: Request, - res: Response -): Promise => { - try { - const { projectId, organization, collectionNodeId } = req.params; - if (!organization || !projectId || !collectionNodeId) { - res.status(400).json({ - message: "All fields are required", - }); - return; - } - const data = { - organization, - projectId, - collectionNodeId, - }; - const result = await GetcollectionNode(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", - }); - } -}; -export const DeleteCollectionsController = async ( - req: Request, - res: Response -): Promise => { - try { - const { organization, projectId, collectionNodeId } = req.params; - if (!organization || !projectId || !collectionNodeId) { - res.status(400).json({ - message: "All fields are required", - }); - return; - } - const data = { - organization, - projectId, - collectionNodeId, - }; - const result = await delCollection(data); - switch (result.status) { - case "project not found": - res.status(200).json({ - message: "project not found", - }); - break; - case "Collection not found": - res.status(200).json({ - message: "Collection not found", - }); - break; - case "Success": - res.status(200).json({ message: "Collection deleted successfully" }); - break; - default: - res.status(500).json({ - message: "Internal server error", - }); - break; - } - } catch (error) { - res.status(500).json({ - message: "Unknown error", - }); - } -}; -export const DuplicateNodeCollectionController = async ( - req: Request, - res: Response -): Promise => { - try { - const { collectionNodeId } = req.params; - const { projectId, organization, collectionName, position, attributes } = - req.body; - if (!organization || !projectId || !collectionNodeId) { - res.status(400).json({ - message: "All fields are required", - }); - return; - } - const data = { - organization, - projectId, - collectionName, - position, - attributes, - collectionNodeId, - }; - const result = await DuplicateCollection(data); - switch (result.status) { - case "project not found": - res.status(200).json({ - message: "project not found", - }); - break; - case "Duplication unsuccessfull": - res.status(200).json({ - message: "Duplication unsuccessfull", - }); - break; - case "Success": - res.status(200).json({ message: "Duplicated successfully" }); - 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 => { - 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({ Collections: result.data }); - break; - default: - res.status(500).json({ - message: "Internal server error", - }); - break; - } - } catch (error) { - res.status(500).json({ - message: "Unknown error", - }); - } -}; - -export const AddAttributesController = async ( - req: Request, - res: Response -): Promise => { - try { - const { collectionNodeId } = req.params; - const { organization, projectId, attributes } = req.body; - if (!organization || !projectId || !attributes || !collectionNodeId) { - res.status(400).json({ - message: "All fields are required", - }); - return; - } - const data = { - organization, - projectId, - collectionNodeId, - attributes, - }; - const result = await addAttributes(data); - switch (result.status) { - case "project not found": - res.status(200).json({ - message: "project not found", - }); - break; - case "Collection not found": - res.status(200).json({ - message: "Collection not found", - }); - break; - case "Success": - res.status(200).json({ - message: "collection Attributes Added", - }); - break; - default: - res.status(500).json({ - message: "Internal server error", - }); - break; - } - } catch (error) { - res.status(500).json({ - message: "Unknown error", - }); - } -}; -export const updateAttributesCollections = async ( - req: Request, - res: Response -): Promise => { - try { - const { collectionNodeId, attributeId } = req.params; - const { - organization, - projectId, - required, - defaultValue, - unique, - index, - key, - type, - } = req.body; - if (!organization || !projectId || !collectionNodeId || !attributeId) { - res.status(400).json({ - message: "All fields are required", - }); - return; - } - const data = { - organization, - projectId, - collectionNodeId, - attributeId, - required, - defaultValue, - unique, - index, - key, - type, - }; - const result = await UpdateAttributes(data); - switch (result.status) { - case "project not found": - res.status(200).json({ - message: "project not found", - }); - break; - case "Collection not found": - res.status(200).json({ - message: "Collection not found", - }); - break; - case "Success": - res.status(200).json({ message: "Field updated successfully" }); - break; - default: - res.status(500).json({ - message: "Internal server error", - }); - break; - } - } catch (error) { - res.status(500).json({ - message: "Unknown error", - }); - } -}; - -export const delAttributesCollections = async ( - req: Request, - res: Response -): Promise => { - try { - const { collectionNodeId } = req.params; - const { organization, projectId, AttributeId } = req.body; - if (!organization || !projectId || !collectionNodeId || !AttributeId) { - res.status(400).json({ - message: "All fields are required", - }); - return; - } - const data = { - organization, - projectId, - collectionNodeId, - AttributeId, - }; - const result = await DelAttributes(data); - switch (result.status) { - case "project not found": - res.status(200).json({ - message: "project not found", - }); - break; - case "Collection not found": - res.status(200).json({ - message: "Collection not found", - Collections: result.data, - }); - break; - case "Success": - res.status(200).json({ message: "Field deleted successfully" }); - break; - default: - res.status(500).json({ - message: "Internal server error", - }); - break; - } - } catch (error) { - res.status(500).json({ - message: "Unknown error", - }); - } -}; - +import { Request, Response } from "express"; +import { + addAttributes, + DelAttributes, + delCollection, + DuplicateCollection, + GetcollectionNode, + GetNodesInProject, + Nodecreation, + SetCollectionName, + UpdateAttributes, +} from "../../shared/services/collectionService"; + +export const NodeCreationController = async ( + req: Request, + res: Response +): Promise => { + try { + const { organization, projectId, position } = req.body; + if (!organization || !projectId || !position) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const data = { + organization, + projectId, + position, + }; + const result = await Nodecreation(data); + + switch (result.status) { + case "project not found": + res.status(200).json({ + message: "project not found", + }); + break; + case "Collection node creation unsuccessfull": + res.status(200).json({ + message: "Collection node creation unsuccessfull", + }); + break; + case "Success": + res.status(200).json({ + message: "Node 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 SetCollectionNameController = async ( + req: Request, + res: Response +): Promise => { + try { + const { + organization, + projectId, + collectionNodeId, + collectionName, + position, + } = req.body; + if (!organization || !projectId || !collectionName || !collectionNodeId) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const data = { + organization, + projectId, + collectionNodeId, + collectionName, + position, + }; + const result = await SetCollectionName(data); + + switch (result.status) { + case "project not found": + res.status(200).json({ + message: "project not found", + }); + break; + case "Collection not found": + res.status(200).json({ + message: "Collection not found", + }); + break; + case "Success": + res.status(200).json({ + message: "collection name updated", + }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + } +}; +export const CollectionDatas = async ( + req: Request, + res: Response +): Promise => { + try { + const { projectId, organization, collectionNodeId } = req.params; + if (!organization || !projectId || !collectionNodeId) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const data = { + organization, + projectId, + collectionNodeId, + }; + const result = await GetcollectionNode(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", + }); + } +}; +export const DeleteCollectionsController = async ( + req: Request, + res: Response +): Promise => { + try { + const { organization, projectId, collectionNodeId } = req.params; + if (!organization || !projectId || !collectionNodeId) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const data = { + organization, + projectId, + collectionNodeId, + }; + const result = await delCollection(data); + switch (result.status) { + case "project not found": + res.status(200).json({ + message: "project not found", + }); + break; + case "Collection not found": + res.status(200).json({ + message: "Collection not found", + }); + break; + case "Success": + res.status(200).json({ message: "Collection deleted successfully" }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + } +}; +export const DuplicateNodeCollectionController = async ( + req: Request, + res: Response +): Promise => { + try { + const { collectionNodeId } = req.params; + const { projectId, organization, collectionName, position, attributes } = + req.body; + if (!organization || !projectId || !collectionNodeId) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const data = { + organization, + projectId, + collectionName, + position, + attributes, + collectionNodeId, + }; + const result = await DuplicateCollection(data); + switch (result.status) { + case "project not found": + res.status(200).json({ + message: "project not found", + }); + break; + case "Duplication unsuccessfull": + res.status(200).json({ + message: "Duplication unsuccessfull", + }); + break; + case "Success": + res.status(200).json({ message: "Duplicated successfully" }); + 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 => { + 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({ Collections: result.data }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + } +}; + +export const AddAttributesController = async ( + req: Request, + res: Response +): Promise => { + try { + const { collectionNodeId } = req.params; + const { organization, projectId, attributes } = req.body; + if (!organization || !projectId || !attributes || !collectionNodeId) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const data = { + organization, + projectId, + collectionNodeId, + attributes, + }; + const result = await addAttributes(data); + switch (result.status) { + case "project not found": + res.status(200).json({ + message: "project not found", + }); + break; + case "Collection not found": + res.status(200).json({ + message: "Collection not found", + }); + break; + case "Success": + res.status(200).json({ + message: "collection Attributes Added", + }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + } +}; +export const updateAttributesCollections = async ( + req: Request, + res: Response +): Promise => { + try { + const { collectionNodeId, attributeId } = req.params; + const { + organization, + projectId, + required, + defaultValue, + unique, + index, + key, + type, + } = req.body; + if (!organization || !projectId || !collectionNodeId || !attributeId) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const data = { + organization, + projectId, + collectionNodeId, + attributeId, + required, + defaultValue, + unique, + index, + key, + type, + }; + const result = await UpdateAttributes(data); + switch (result.status) { + case "project not found": + res.status(200).json({ + message: "project not found", + }); + break; + case "Collection not found": + res.status(200).json({ + message: "Collection not found", + }); + break; + case "Success": + res.status(200).json({ message: "Field updated successfully" }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + } +}; + +export const delAttributesCollections = async ( + req: Request, + res: Response +): Promise => { + try { + const { collectionNodeId } = req.params; + const { organization, projectId, AttributeId } = req.body; + if (!organization || !projectId || !collectionNodeId || !AttributeId) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const data = { + organization, + projectId, + collectionNodeId, + AttributeId, + }; + const result = await DelAttributes(data); + switch (result.status) { + case "project not found": + res.status(200).json({ + message: "project not found", + }); + break; + case "Collection not found": + res.status(200).json({ + message: "Collection not found", + Collections: result.data, + }); + break; + case "Success": + res.status(200).json({ message: "Field deleted successfully" }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + } +}; + diff --git a/src/api-server/controller/edgeController.ts b/src/api-server/controller/edgeController.ts index 4163099..d58bddd 100644 --- a/src/api-server/controller/edgeController.ts +++ b/src/api-server/controller/edgeController.ts @@ -1,157 +1,157 @@ -import { Request, Response } from "express"; -import { Alledges, deleteEdge, edgecreation } from "../../shared/services/edgeService"; -export const edgeCreationController = async ( - req: Request, - res: Response -): Promise => { - 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 => { - 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 => { - 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", - }); - } +import { Request, Response } from "express"; +import { Alledges, deleteEdge, edgecreation } from "../../shared/services/edgeService"; +export const edgeCreationController = async ( + req: Request, + res: Response +): Promise => { + 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 => { + 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 => { + 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", + }); + } }; \ No newline at end of file diff --git a/src/api-server/controller/fileModelController.ts b/src/api-server/controller/fileModelController.ts index 52de007..42eb214 100644 --- a/src/api-server/controller/fileModelController.ts +++ b/src/api-server/controller/fileModelController.ts @@ -1,95 +1,95 @@ -import fs from "node:fs"; -import { Request, Response } from "express"; -import path from "path"; -import baseType from "../../shared/model/projectmodel"; -import FileMode from "../../shared/model/collectionModel"; -export const fileModelCreatecontroller = async ( - req: Request, - res: Response -): Promise => { - const { pathName, baseId, modelName, organization, attributes } = req.body; - - try { - const findBaseName = await baseType(organization).findById(baseId); - - const attrToSchema = (attr: any) => { - const mapType: any = { - string: "String", - number: "Number", - boolean: "Boolean", - }; - const lines = []; - for (const [key, config] of Object.entries(attr)) { - const line: string[] = []; - line.push(`${key}: {`); - line.push(` type: ${mapType[(config as any).type] || "String"},`); - if ((config as any).required) line.push(` required: true,`); - if ((config as any).default !== undefined) - line.push(` default: ${(config as any).default},`); - if ((config as any).minLength) - line.push(` minlength: ${(config as any).minLength},`); - if ((config as any).maxLength) - line.push(` maxlength: ${(config as any).maxLength},`); - if ((config as any).min !== undefined) - line.push(` min: ${(config as any).min},`); - if ((config as any).max !== undefined) - line.push(` max: ${(config as any).max},`); - line.push("},"); - lines.push(line.join("\n")); - } - return lines.join("\n"); - }; - const schemaCode = ` -import mongoose from 'mongoose'; - -const ${modelName}Schema = new mongoose.Schema({ -${attrToSchema(attributes)} -}); - -export const ${modelName} = mongoose.model('${modelName}', ${modelName}Schema); -`; - - const basePath = path.join( - pathName, - findBaseName.BaseName, - "src", - "Models" - ); - const modelFilePath = path.join(basePath, `${modelName}SchemaModel.ts`); - - // Read all subfolders inside basePath - if (!fs.existsSync(basePath)) { - fs.mkdirSync(basePath, { recursive: true }); - } - - fs.writeFileSync(modelFilePath, schemaCode.trim()); - - return res - .status(200) - .json({ message: "Model file created successfully." }); - - // const folders = ["Controller", "Routes", "Models", "Services"]; - - // if (!fs.existsSync(basePath)) { - // fs.mkdirSync(basePath, { recursive: true }); - // console.log(`Created root path: ${basePath}`); - // } - // folders.forEach(async (folder) => { - // const fullPath = path.join(basePath, folder); - // if (!fs.existsSync(fullPath)) { - // fs.mkdirSync(fullPath, { recursive: true }); - // const BaseDataSave = await FileMode(organization).create({ - // baseId, - // modelName, - // attributes, - - // }); - // } else { - // res.send(`Folder already exists: ${fullPath}`); - // console.log(`Folder already exists: ${folder}`); - // } - // }); - } catch (error: unknown) { - res.send(error); - } -}; +import fs from "node:fs"; +import { Request, Response } from "express"; +import path from "path"; +import baseType from "../../shared/model/projectmodel"; +import FileMode from "../../shared/model/collectionModel"; +export const fileModelCreatecontroller = async ( + req: Request, + res: Response +): Promise => { + const { pathName, baseId, modelName, organization, attributes } = req.body; + + try { + const findBaseName = await baseType(organization).findById(baseId); + + const attrToSchema = (attr: any) => { + const mapType: any = { + string: "String", + number: "Number", + boolean: "Boolean", + }; + const lines = []; + for (const [key, config] of Object.entries(attr)) { + const line: string[] = []; + line.push(`${key}: {`); + line.push(` type: ${mapType[(config as any).type] || "String"},`); + if ((config as any).required) line.push(` required: true,`); + if ((config as any).default !== undefined) + line.push(` default: ${(config as any).default},`); + if ((config as any).minLength) + line.push(` minlength: ${(config as any).minLength},`); + if ((config as any).maxLength) + line.push(` maxlength: ${(config as any).maxLength},`); + if ((config as any).min !== undefined) + line.push(` min: ${(config as any).min},`); + if ((config as any).max !== undefined) + line.push(` max: ${(config as any).max},`); + line.push("},"); + lines.push(line.join("\n")); + } + return lines.join("\n"); + }; + const schemaCode = ` +import mongoose from 'mongoose'; + +const ${modelName}Schema = new mongoose.Schema({ +${attrToSchema(attributes)} +}); + +export const ${modelName} = mongoose.model('${modelName}', ${modelName}Schema); +`; + + const basePath = path.join( + pathName, + findBaseName.BaseName, + "src", + "Models" + ); + const modelFilePath = path.join(basePath, `${modelName}SchemaModel.ts`); + + // Read all subfolders inside basePath + if (!fs.existsSync(basePath)) { + fs.mkdirSync(basePath, { recursive: true }); + } + + fs.writeFileSync(modelFilePath, schemaCode.trim()); + + return res + .status(200) + .json({ message: "Model file created successfully." }); + + // const folders = ["Controller", "Routes", "Models", "Services"]; + + // if (!fs.existsSync(basePath)) { + // fs.mkdirSync(basePath, { recursive: true }); + // console.log(`Created root path: ${basePath}`); + // } + // folders.forEach(async (folder) => { + // const fullPath = path.join(basePath, folder); + // if (!fs.existsSync(fullPath)) { + // fs.mkdirSync(fullPath, { recursive: true }); + // const BaseDataSave = await FileMode(organization).create({ + // baseId, + // modelName, + // attributes, + + // }); + // } else { + // res.send(`Folder already exists: ${fullPath}`); + // console.log(`Folder already exists: ${folder}`); + // } + // }); + } catch (error: unknown) { + res.send(error); + } +}; diff --git a/src/api-server/controller/projectController.ts b/src/api-server/controller/projectController.ts index 9771fd8..fa02875 100644 --- a/src/api-server/controller/projectController.ts +++ b/src/api-server/controller/projectController.ts @@ -1,168 +1,168 @@ -import { Request, Response } from "express"; -import { - GetNodesInProject, - projectCreationService, - projectDatas, -} from "../../shared/services/projectService"; - -export const projectCreationController = async ( - req: Request, - res: Response -): Promise => { - 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 => { - 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 => { - 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", - }); - } +import { Request, Response } from "express"; +import { + GetNodesInProject, + projectCreationService, + projectDatas, +} from "../../shared/services/projectService"; + +export const projectCreationController = async ( + req: Request, + res: Response +): Promise => { + 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 => { + 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 => { + 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", + }); + } }; \ No newline at end of file diff --git a/src/api-server/main.ts b/src/api-server/main.ts index ff0099c..5726894 100644 --- a/src/api-server/main.ts +++ b/src/api-server/main.ts @@ -1,5 +1,5 @@ -import app from "./app"; -const port = process.env.API_PORT; -app.listen(port, () => { - console.log(`Port is running on the ${port}`); -}); +import app from "./app"; +const port = process.env.API_PORT; +app.listen(port, () => { + console.log(`Port is running on the ${port}`); +}); diff --git a/src/api-server/routes/collectionRoutes.ts b/src/api-server/routes/collectionRoutes.ts index 2ccd0e2..f8453ca 100644 --- a/src/api-server/routes/collectionRoutes.ts +++ b/src/api-server/routes/collectionRoutes.ts @@ -1,58 +1,58 @@ -import express from "express"; -import { - AddAttributesController, - CollectionDatas, - delAttributesCollections, - DeleteCollectionsController, - DuplicateNodeCollectionController, - NodeCreationController, - NodesCollectionsBasedOnproject, - SetCollectionNameController, - updateAttributesCollections, -} from "../controller/collectionNodeController"; - -const collectionNodeRoutes = express.Router(); -//Node creation -collectionNodeRoutes.post("/nodes", NodeCreationController); -//collection Added -collectionNodeRoutes.patch( - "/nodes/collectionName", - SetCollectionNameController -); -//duplicate collection -collectionNodeRoutes.post( - "/nodes/:collectionNodeId/duplicate", - DuplicateNodeCollectionController -); -//particular collection data -collectionNodeRoutes.get( - "/nodes/:organization/:projectId/:collectionNodeId", - CollectionDatas -); -//delete collection -collectionNodeRoutes.patch( - "/nodes/:organization/:projectId/:collectionNodeId", - DeleteCollectionsController -); - -//Add fields -collectionNodeRoutes.patch( - "/nodes/:collectionNodeId/attributes", - AddAttributesController -); -//Collections and fiels based on the project -collectionNodeRoutes.get( - "/nodes/:organization/:projectId", - NodesCollectionsBasedOnproject -); -//update fields -collectionNodeRoutes.patch( - "/nodes/:collectionNodeId/attributes/:attributeId", - updateAttributesCollections -); -//delete fields -collectionNodeRoutes.patch( - "/nodes/:collectionNodeId/attributes/softDelete", - delAttributesCollections -); -export default collectionNodeRoutes; +import express from "express"; +import { + AddAttributesController, + CollectionDatas, + delAttributesCollections, + DeleteCollectionsController, + DuplicateNodeCollectionController, + NodeCreationController, + NodesCollectionsBasedOnproject, + SetCollectionNameController, + updateAttributesCollections, +} from "../controller/collectionNodeController"; + +const collectionNodeRoutes = express.Router(); +//Node creation +collectionNodeRoutes.post("/nodes", NodeCreationController); +//collection Added +collectionNodeRoutes.patch( + "/nodes/collectionName", + SetCollectionNameController +); +//duplicate collection +collectionNodeRoutes.post( + "/nodes/:collectionNodeId/duplicate", + DuplicateNodeCollectionController +); +//particular collection data +collectionNodeRoutes.get( + "/nodes/:organization/:projectId/:collectionNodeId", + CollectionDatas +); +//delete collection +collectionNodeRoutes.patch( + "/nodes/:organization/:projectId/:collectionNodeId", + DeleteCollectionsController +); + +//Add fields +collectionNodeRoutes.patch( + "/nodes/:collectionNodeId/attributes", + AddAttributesController +); +//Collections and fiels based on the project +collectionNodeRoutes.get( + "/nodes/:organization/:projectId", + NodesCollectionsBasedOnproject +); +//update fields +collectionNodeRoutes.patch( + "/nodes/:collectionNodeId/attributes/:attributeId", + updateAttributesCollections +); +//delete fields +collectionNodeRoutes.patch( + "/nodes/:collectionNodeId/attributes/softDelete", + delAttributesCollections +); +export default collectionNodeRoutes; diff --git a/src/api-server/routes/edgeRoutes.ts b/src/api-server/routes/edgeRoutes.ts index b9cd86a..38ad439 100644 --- a/src/api-server/routes/edgeRoutes.ts +++ b/src/api-server/routes/edgeRoutes.ts @@ -1,8 +1,8 @@ -import express from "express"; -import { allEdgesController, deleteEdgesController, edgeCreationController } from "../controller/edgeController"; -const edgeRoutes = express.Router(); - -edgeRoutes.post("/edgeCreate", edgeCreationController); -edgeRoutes.patch("/edgeDelete", deleteEdgesController); -edgeRoutes.get("/allEdges", allEdgesController); -export default edgeRoutes; +import express from "express"; +import { allEdgesController, deleteEdgesController, edgeCreationController } from "../controller/edgeController"; +const edgeRoutes = express.Router(); + +edgeRoutes.post("/edgeCreate", edgeCreationController); +edgeRoutes.patch("/edgeDelete", deleteEdgesController); +edgeRoutes.get("/allEdges", allEdgesController); +export default edgeRoutes; diff --git a/src/api-server/routes/projectRoutes.ts b/src/api-server/routes/projectRoutes.ts index 8441c61..da4628a 100644 --- a/src/api-server/routes/projectRoutes.ts +++ b/src/api-server/routes/projectRoutes.ts @@ -1,12 +1,12 @@ -import express from "express"; -import { NodesCollectionsBasedOnproject, projectCreationController } from "../controller/projectController"; - -const projectRoutes = express.Router(); - -projectRoutes.post("/Newproject", projectCreationController); -projectRoutes.get( - "/nodes/:organization/:projectId", - NodesCollectionsBasedOnproject -); -// appRoutes.post("/createfileModel", fileModelCreatecontroller); -export default projectRoutes; +import express from "express"; +import { NodesCollectionsBasedOnproject, projectCreationController } from "../controller/projectController"; + +const projectRoutes = express.Router(); + +projectRoutes.post("/Newproject", projectCreationController); +projectRoutes.get( + "/nodes/:organization/:projectId", + NodesCollectionsBasedOnproject +); +// appRoutes.post("/createfileModel", fileModelCreatecontroller); +export default projectRoutes; diff --git a/src/shared/connection/connection.ts b/src/shared/connection/connection.ts index 6a76248..5db917e 100644 --- a/src/shared/connection/connection.ts +++ b/src/shared/connection/connection.ts @@ -1,50 +1,50 @@ -import mongoose, { Schema, Connection, Model } from "mongoose"; -import dotenv from "dotenv"; -interface ConnectionCache { - [key: string]: Connection; -} - -const connections: ConnectionCache = {}; -dotenv.config({ quiet: true }); -const MainModel = ( - db: string, - modelName: string, - schema: Schema, - collectionName: string -): Model => { - const db1_url = `${process.env.MONGO_URI}${db}`; - const authOptions = { - user: process.env.MONGO_USER, - pass: process.env.MONGO_PASSWORD, - authSource: process.env.MONGO_AUTH_DB || "admin", - maxPoolSize: 50, - }; - - if (connections[db]) { - return connections[db].model(modelName, schema, collectionName); - } - - try { - const db1 = mongoose.createConnection(db1_url, authOptions); - - connections[db] = db1; - - db1.on("connected", () => { - console.log(`Connected to MongoDB database: ${db}`); - }); - - db1.on("error", (err) => { - console.error( - `MongoDB connection error for database ${db}:`, - err.message - ); - }); - - return db1.model(modelName, schema, collectionName); - } catch (error) { - console.error("Database connection error:", (error as Error).message); - throw error; - } -}; - -export default MainModel; +import mongoose, { Schema, Connection, Model } from "mongoose"; +import dotenv from "dotenv"; +interface ConnectionCache { + [key: string]: Connection; +} + +const connections: ConnectionCache = {}; +dotenv.config({ quiet: true }); +const MainModel = ( + db: string, + modelName: string, + schema: Schema, + collectionName: string +): Model => { + const db1_url = `${process.env.MONGO_URI}${db}`; + const authOptions = { + user: process.env.MONGO_USER, + pass: process.env.MONGO_PASSWORD, + authSource: process.env.MONGO_AUTH_DB || "admin", + maxPoolSize: 50, + }; + + if (connections[db]) { + return connections[db].model(modelName, schema, collectionName); + } + + try { + const db1 = mongoose.createConnection(db1_url, authOptions); + + connections[db] = db1; + + db1.on("connected", () => { + console.log(`Connected to MongoDB database: ${db}`); + }); + + db1.on("error", (err) => { + console.error( + `MongoDB connection error for database ${db}:`, + err.message + ); + }); + + return db1.model(modelName, schema, collectionName); + } catch (error) { + console.error("Database connection error:", (error as Error).message); + throw error; + } +}; + +export default MainModel; diff --git a/src/shared/model/collectionModel.ts b/src/shared/model/collectionModel.ts index becae61..481d7f6 100644 --- a/src/shared/model/collectionModel.ts +++ b/src/shared/model/collectionModel.ts @@ -1,73 +1,73 @@ -import { Schema, Document } from "mongoose"; -import MainModel from "../connection/connection"; -import { IProject } from "./projectmodel"; -type IattributeTypes = - | "string" - | "any" - | "Array" - | "Date" - | "Enum" - | "undefined" - | "object" - | "ObjectId" - | "number" - | "boolean"; - -interface IAttributes { - isArchive: boolean; - key: string; - type: IattributeTypes; - refKey?: object; - required?: boolean; - default?: any; - unique?: boolean; - index?: boolean; -} -interface ICollectionNode extends Document { - projectId: IProject["_id"]; - collectionNodeName: string; - attributes: IAttributes[]; - isArchive: boolean; - position: [number, number, number]; -} -const attributeSchema = new Schema({ - key: { type: String, required: true }, - type: { - type: String, - required: true, - enum: [ - "string", - "number", - "boolean", - "Date", - "ObjectId", - "Array", - "Enum", - "object", - "any", - ], - }, - required: { type: Boolean }, - refKey: { type: Object }, - default: { type: Schema.Types.Mixed }, - unique: { type: Boolean }, - index: { type: Boolean }, - isArchive: { type: Boolean, default: false }, -}); -const collectionSchema: Schema = new Schema( - { - projectId: { type: Schema.Types.ObjectId, ref: "Project" }, - collectionNodeName: { type: String }, - position: { type: [Number], required: true }, - isArchive: { type: Boolean, default: false }, - attributes: [attributeSchema], - }, - { - timestamps: true, - } -); - -const collectionsModel = (db: any) => { - return MainModel(db, "collectionNode", collectionSchema, "collectionNode"); -}; +import { Schema, Document } from "mongoose"; +import MainModel from "../connection/connection"; +import { IProject } from "./projectmodel"; +type IattributeTypes = + | "string" + | "any" + | "Array" + | "Date" + | "Enum" + | "undefined" + | "object" + | "ObjectId" + | "number" + | "boolean"; + +interface IAttributes { + isArchive: boolean; + key: string; + type: IattributeTypes; + refKey?: object; + required?: boolean; + default?: any; + unique?: boolean; + index?: boolean; +} +interface ICollectionNode extends Document { + projectId: IProject["_id"]; + collectionNodeName: string; + attributes: IAttributes[]; + isArchive: boolean; + position: [number, number, number]; +} +const attributeSchema = new Schema({ + key: { type: String, required: true }, + type: { + type: String, + required: true, + enum: [ + "string", + "number", + "boolean", + "Date", + "ObjectId", + "Array", + "Enum", + "object", + "any", + ], + }, + required: { type: Boolean }, + refKey: { type: Object }, + default: { type: Schema.Types.Mixed }, + unique: { type: Boolean }, + index: { type: Boolean }, + isArchive: { type: Boolean, default: false }, +}); +const collectionSchema: Schema = new Schema( + { + projectId: { type: Schema.Types.ObjectId, ref: "Project" }, + collectionNodeName: { type: String }, + position: { type: [Number], required: true }, + isArchive: { type: Boolean, default: false }, + attributes: [attributeSchema], + }, + { + timestamps: true, + } +); + +const collectionsModel = (db: any) => { + return MainModel(db, "collectionNode", collectionSchema, "collectionNode"); +}; export default collectionsModel; \ No newline at end of file diff --git a/src/shared/model/edgeModel.ts b/src/shared/model/edgeModel.ts index 4e7ba01..fb0c2d7 100644 --- a/src/shared/model/edgeModel.ts +++ b/src/shared/model/edgeModel.ts @@ -1,29 +1,29 @@ -import { Schema, Document } from "mongoose"; -import MainModel from "../connection/connection"; -import { IProject } from "./projectmodel"; -interface IEdgeModel extends Document { - projectId: IProject["_id"]; - from: { collection_id: string; field: string }; - to: { collection_id: string }; - cardinality: "one-to-one" | "one-to-many"|"many-to-many" - isArchive: boolean; - createdAt: number; - -} -const EdgeSchema = new Schema({ - projectId: { type: Schema.Types.ObjectId, ref: "Project", required: true }, - from: { - collection_id: { type: String, required: true }, - field: { type: String, required: true }, - }, - to: { - collection_id: { type: String, required: true }, - }, - cardinality: { type: String, enum: ["one-to-one", "one-to-many", "many-to-many"], required: true }, - isArchive: { type: Boolean, default: false }, - createdAt: { type: Number, default: Date.now }, -}); -const edgeModel = (db: any) => { - return MainModel(db, "edge", EdgeSchema, "edge"); -}; -export default edgeModel; +import { Schema, Document } from "mongoose"; +import MainModel from "../connection/connection"; +import { IProject } from "./projectmodel"; +interface IEdgeModel extends Document { + projectId: IProject["_id"]; + from: { collection_id: string; field: string }; + to: { collection_id: string }; + cardinality: "one-to-one" | "one-to-many"|"many-to-many" + isArchive: boolean; + createdAt: number; + +} +const EdgeSchema = new Schema({ + projectId: { type: Schema.Types.ObjectId, ref: "Project", required: true }, + from: { + collection_id: { type: String, required: true }, + field: { type: String, required: true }, + }, + to: { + collection_id: { type: String, required: true }, + }, + cardinality: { type: String, enum: ["one-to-one", "one-to-many", "many-to-many"], required: true }, + isArchive: { type: Boolean, default: false }, + createdAt: { type: Number, default: Date.now }, +}); +const edgeModel = (db: any) => { + return MainModel(db, "edge", EdgeSchema, "edge"); +}; +export default edgeModel; diff --git a/src/shared/model/mvcModel.ts b/src/shared/model/mvcModel.ts index 2bc7e6d..49ac3bf 100644 --- a/src/shared/model/mvcModel.ts +++ b/src/shared/model/mvcModel.ts @@ -1,38 +1,38 @@ -import { Schema, Document } from "mongoose"; -import MainModel from "../connection/connection"; -import { IProject } from "./projectmodel"; -interface Ifolders extends Document { - folderName: string; - createdAt: number; -} -const folderSchema: Schema = new Schema({ - folderName: { type: String, required: true }, - createdAt: { type: Date, default: Date.now }, -}); -export interface IMVCPrject extends Document { - projectId: IProject["_id"]; - controllers: boolean; - routes: boolean; - models: boolean; - services: boolean; - middleware: boolean; - utils: boolean; - config: boolean; - folders: Ifolders[]; -} -const mvcSchema: Schema = new Schema({ - projectId: { type: Schema.Types.ObjectId, ref: "Project" }, - controllers: { type: Boolean }, - routes: { type: Boolean }, - models: { type: Boolean }, - services: { type: Boolean }, - middleware: { type: Boolean }, - utils: { type: Boolean }, - config: { type: Boolean }, - folders: [folderSchema], -}); - -const MVCarcModel = (db: any) => { - return MainModel(db, "MVC", mvcSchema, "MVC"); -}; -export default MVCarcModel; +import { Schema, Document } from "mongoose"; +import MainModel from "../connection/connection"; +import { IProject } from "./projectmodel"; +interface Ifolders extends Document { + folderName: string; + createdAt: number; +} +const folderSchema: Schema = new Schema({ + folderName: { type: String, required: true }, + createdAt: { type: Date, default: Date.now }, +}); +export interface IMVCPrject extends Document { + projectId: IProject["_id"]; + controllers: boolean; + routes: boolean; + models: boolean; + services: boolean; + middleware: boolean; + utils: boolean; + config: boolean; + folders: Ifolders[]; +} +const mvcSchema: Schema = new Schema({ + projectId: { type: Schema.Types.ObjectId, ref: "Project" }, + controllers: { type: Boolean }, + routes: { type: Boolean }, + models: { type: Boolean }, + services: { type: Boolean }, + middleware: { type: Boolean }, + utils: { type: Boolean }, + config: { type: Boolean }, + folders: [folderSchema], +}); + +const MVCarcModel = (db: any) => { + return MainModel(db, "MVC", mvcSchema, "MVC"); +}; +export default MVCarcModel; diff --git a/src/shared/model/projectmodel.ts b/src/shared/model/projectmodel.ts index 9446d48..d3dd7fd 100644 --- a/src/shared/model/projectmodel.ts +++ b/src/shared/model/projectmodel.ts @@ -1,43 +1,43 @@ -import { Schema, Document } from "mongoose"; -import MainModel from "../connection/connection"; -export interface IProject extends Document { - projectName: string; - appType: string; - slug: string; - isArchive: boolean; - createdBy: string; - description: string; - members: [string]; - useableLanguage: string; - typeOfDB: string; - DBName: string; - architecture: string; - apiType: string; -} -const projectSchema: Schema = new Schema( - { - projectName: { type: String }, - appType:{type:String,enum:["Backend","Frontend"]}, - slug: { type: String }, - isArchive: { type: Boolean, default: false }, - createdBy: { type: String }, - description: { type: String }, - DBName: { type: String }, - typeOfDB: { type: String }, - useableLanguage: { type: String }, - architecture: { type: String }, - apiType: { - type: String, - enum: ["RESTful", "SOAP", "GraphQL", "RPC", "WebSocket"], - }, - members: { type: [String] }, - }, - { - timestamps: true, - } -); - -const ProjectType = (db: any) => { - return MainModel(db, "Project", projectSchema, "Project"); -}; -export default ProjectType; +import { Schema, Document } from "mongoose"; +import MainModel from "../connection/connection"; +export interface IProject extends Document { + projectName: string; + appType: string; + slug: string; + isArchive: boolean; + createdBy: string; + description: string; + members: [string]; + useableLanguage: string; + typeOfDB: string; + DBName: string; + architecture: string; + apiType: string; +} +const projectSchema: Schema = new Schema( + { + projectName: { type: String }, + appType:{type:String,enum:["Backend","Frontend"]}, + slug: { type: String }, + isArchive: { type: Boolean, default: false }, + createdBy: { type: String }, + description: { type: String }, + DBName: { type: String }, + typeOfDB: { type: String }, + useableLanguage: { type: String }, + architecture: { type: String }, + apiType: { + type: String, + enum: ["RESTful", "SOAP", "GraphQL", "RPC", "WebSocket"], + }, + members: { type: [String] }, + }, + { + timestamps: true, + } +); + +const ProjectType = (db: any) => { + return MainModel(db, "Project", projectSchema, "Project"); +}; +export default ProjectType; diff --git a/src/shared/services/collectionService.ts b/src/shared/services/collectionService.ts index 3e54f16..d664aa8 100644 --- a/src/shared/services/collectionService.ts +++ b/src/shared/services/collectionService.ts @@ -1,559 +1,559 @@ -import mongoose from "mongoose"; -import ProjectType from "../../shared/model/projectmodel"; -import collectionsModel from "../model/collectionModel"; -interface Iresponse { - status: string; - data?: any; -} -interface IcollectionNode { - projectId: string; - organization: string; - position: [number]; -} -interface IAttribute { - key: string; - type: any; -} -interface IcollectionNodeName { - projectId: string; - organization: string; - collectionNodeId: string; - collectionName: string; - position: [number]; -} -interface IcollectionAttributes { - projectId: string; - organization: string; - collectionNodeId: string; - attributes: IAttribute[]; -} -interface IcollectionNodes { - projectId: string; - organization: string; -} -interface IcollectionNodeById { - projectId: string; - organization: string; - collectionNodeId: string; -} -interface IAttributesEdit { - projectId: string; - organization: string; - collectionNodeId: string; - attributeId: string; - key?: string; - type?: string; - required?: boolean; - defaultValue?: any; - unique?: boolean; - index?: boolean; -} -interface IAttributesDel { - projectId: string; - organization: string; - collectionNodeId: string; - AttributeId: string; -} -interface ICollectionDelete { - projectId: string; - organization: string; - collectionNodeId: string; -} -interface IDuplicateCollectionNode { - projectId: string; - collectionNodeId: string; - organization: string; - collectionName: string; - position: [number]; - attributes: []; -} - -export const Nodecreation = async ( - data: IcollectionNode -): Promise => { - const { organization, projectId, position } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - isArchive: false, - }); - if (!existingProject) { - return { status: "project not found" }; - } else { - const newCollectionnode = await collectionsModel(organization).create({ - projectId: projectId, - isArchive: false, - position: position, - }); - if (!newCollectionnode) - return { status: "Collection node creation unsuccessfull" }; - else return { status: "Success", data: newCollectionnode._id }; - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -export const SetCollectionName = async ( - data: IcollectionNodeName -): Promise => { - const { - organization, - projectId, - position, - collectionNodeId, - collectionName, - } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - isArchive: false, - }); - if (!existingProject) { - return { status: "project not found" }; - } else { - const existingCollection = await collectionsModel(organization).findOne({ - projectId: projectId, - isArchive: false, - _id: collectionNodeId, - }); - if (!existingCollection) { - return { status: "Collection not found" }; - } - const collectionNameupdate = await collectionsModel( - organization - ).findOneAndUpdate( - { - projectId: projectId, - isArchive: false, - _id: collectionNodeId, - }, - { collectionNodeName: collectionName }, - { new: true } - ); - return { status: "Success" }; - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -export const addAttributes = async ( - data: IcollectionAttributes -): Promise => { - const { organization, projectId, collectionNodeId, attributes } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - isArchive: false, - }); - if (!existingProject) { - return { status: "project not found" }; - } else { - const existingCollection = await collectionsModel(organization).findOne({ - projectId: projectId, - isArchive: false, - _id: collectionNodeId, - }); - if (!existingCollection) { - return { status: "Collection not found" }; - } - const existingAttributes = existingCollection.attributes || []; - const newAttributes = attributes; - const updatedAttributesMap = new Map(); - - for (const attr of existingAttributes) { - updatedAttributesMap.set(attr.key, attr); - } - - for (const attr of newAttributes) { - if (!updatedAttributesMap.has(attr.key)) { - updatedAttributesMap.set(attr.key, attr); - } - } - - const updatedAttributes = Array.from(updatedAttributesMap.values()); - const AttributesAdded = await collectionsModel( - organization - ).findOneAndUpdate( - { - projectId: projectId, - isArchive: false, - _id: collectionNodeId, - }, - { attributes: updatedAttributes }, - { new: true } - ); - return { status: "Success" }; - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -export const GetNodesInProject = async ( - data: IcollectionNodes -): Promise => { - const { organization, projectId } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - isArchive: false, - }); - if (!existingProject) { - return { status: "project not found" }; - } else { - const collectionNodes = await collectionsModel(organization) - .find({ projectId: projectId, isArchive: false }) - .select("collectionNodeName attributes position -_id "); - if (!collectionNodes) - return { status: "No collection Nodes present", data: [] }; - else { - const formattedCollections = collectionNodes.map((collection) => ({ - position: collection.position, - collectionNodeName: collection.collectionNodeName, - attributes: collection.attributes - .filter((attr: any) => !attr.isArchive) - .map((attr: any) => { - const { isArchive, ...rest } = attr.toObject(); - return { ...rest }; - }), - })); - return { status: "Success", data: formattedCollections }; - } - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -export const UpdateAttributes = async ( - data: IAttributesEdit -): Promise => { - const { - organization, - projectId, - collectionNodeId, - attributeId, - required, - defaultValue, - unique, - index, - key, - type, - } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - isArchive: false, - }); - if (!existingProject) { - return { status: "project not found" }; - } else { - const existingCollection = await collectionsModel(organization).findOne({ - projectId: projectId, - _id: collectionNodeId, - isArchive: false, - }); - if (!existingCollection) return { status: "Collection not found" }; - - const editCollection = await collectionsModel( - organization - ).findOneAndUpdate( - { - projectId: projectId, - isArchive: false, - attributes: { - $elemMatch: { _id: new mongoose.Types.ObjectId(attributeId) }, - }, - }, - { - $set: { - "attributes.$.required": required, - "attributes.$.default": defaultValue, - "attributes.$.index": index, - "attributes.$.unique": unique, - "attributes.$.key": key, - "attributes.$.type": type, - }, - }, - { new: true } - ); - return { status: "Success" }; - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -export const DelAttributes = async ( - data: IAttributesDel -): Promise => { - const { organization, projectId, collectionNodeId, AttributeId } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - isArchive: false, - }); - if (!existingProject) { - return { status: "project not found" }; - } else { - const existingCollection = await collectionsModel(organization).findOne({ - projectId: projectId, - _id: collectionNodeId, - isArchive: false, - }); - if (!existingCollection) return { status: "Collection not found" }; - - const softDeleteAttribute = await collectionsModel( - organization - ).findOneAndUpdate( - { - projectId: projectId, - isArchive: false, - attributes: { - $elemMatch: { - _id: new mongoose.Types.ObjectId(AttributeId), - isArchive: false, - }, - }, - }, - { - $set: { - "attributes.$.isArchive": true, - }, - }, - { new: true } - ); - return { status: "Success" }; - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -export const delCollection = async ( - data: ICollectionDelete -): Promise => { - const { organization, projectId, collectionNodeId } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - isArchive: false, - }); - if (!existingProject) { - return { status: "project not found" }; - } else { - const existingCollection = await collectionsModel(organization).findOne({ - projectId: projectId, - isArchive: false, - _id: collectionNodeId, - }); - if (!existingCollection) { - return { status: "Collection not found" }; - } - const collectionSoftDelete = await collectionsModel( - organization - ).findOneAndUpdate( - { - projectId: projectId, - isArchive: false, - _id: collectionNodeId, - }, - { isArchive: true }, - { new: true } - ); - return { status: "Success" }; - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -export const GetcollectionNode = async ( - data: IcollectionNodeById -): Promise => { - const { organization, projectId, collectionNodeId } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - isArchive: false, - }); - if (!existingProject) { - return { status: "project not found" }; - } else { - const existingCollection = await collectionsModel(organization).findOne({ - projectId: projectId, - isArchive: false, - _id: collectionNodeId, - }); - if (!existingCollection) { - return { status: "Collection not found" }; - } - const formattedCollection = { - position: existingCollection.position, - collectionNodeName: existingCollection.collectionNodeName, - attributes: existingCollection.attributes - .filter((attr: any) => !attr.isArchive) - .map((attr: any) => { - const { isArchive, ...rest } = attr.toObject(); - return rest; - }), - }; - return { status: "Success", data: formattedCollection }; - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -const generateUniqueCollectionName = async ( - baseName: string, - organization: string, - projectId: string -): Promise => { - let nameToTry = baseName; - let attempt = 0; - - while (true) { - const existingCollection = await collectionsModel(organization).findOne({ - projectId, - isArchive: false, - collectionNodeName: nameToTry, - }); - if (!existingCollection) { - return nameToTry; - } - attempt++; - nameToTry = `${baseName} (duplicate${attempt > 1 ? ` ${attempt}` : ""})`; - - if (attempt > 10) { - throw new Error("Too many duplicate project name attempts"); - } - } -}; -export const DuplicateCollection = async ( - data: IDuplicateCollectionNode -): Promise => { - const { organization, projectId, position, collectionNodeId } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - isArchive: false, - }); - if (!existingProject) { - return { status: "project not found" }; - } else { - const existingCollection = await collectionsModel(organization).findOne({ - projectId: projectId, - isArchive: false, - _id: collectionNodeId, - }); - if (!existingCollection) - return { status: "CollectionId not found for duplication" }; - else { - const NewduplicateName = await generateUniqueCollectionName( - existingCollection.collectionNodeName, - organization, - projectId - ); - - const NewCollectionDuplicate = await collectionsModel( - organization - ).create({ - projectId, - isArchive: false, - position, - collectionNodeName: NewduplicateName, - }); - if (!NewCollectionDuplicate) - return { status: "Duplication unsuccessfull" }; - else { - const data = existingCollection.attributes - .filter((attr: any) => !attr.isArchive) - .map((attr: any) => { - const { isArchive, _id, ...rest } = attr.toObject(); - return rest; - }); - NewCollectionDuplicate.attributes = data; - NewCollectionDuplicate.save(); - return { status: "Success" }; - } - } - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; +import mongoose from "mongoose"; +import ProjectType from "../../shared/model/projectmodel"; +import collectionsModel from "../model/collectionModel"; +interface Iresponse { + status: string; + data?: any; +} +interface IcollectionNode { + projectId: string; + organization: string; + position: [number]; +} +interface IAttribute { + key: string; + type: any; +} +interface IcollectionNodeName { + projectId: string; + organization: string; + collectionNodeId: string; + collectionName: string; + position: [number]; +} +interface IcollectionAttributes { + projectId: string; + organization: string; + collectionNodeId: string; + attributes: IAttribute[]; +} +interface IcollectionNodes { + projectId: string; + organization: string; +} +interface IcollectionNodeById { + projectId: string; + organization: string; + collectionNodeId: string; +} +interface IAttributesEdit { + projectId: string; + organization: string; + collectionNodeId: string; + attributeId: string; + key?: string; + type?: string; + required?: boolean; + defaultValue?: any; + unique?: boolean; + index?: boolean; +} +interface IAttributesDel { + projectId: string; + organization: string; + collectionNodeId: string; + AttributeId: string; +} +interface ICollectionDelete { + projectId: string; + organization: string; + collectionNodeId: string; +} +interface IDuplicateCollectionNode { + projectId: string; + collectionNodeId: string; + organization: string; + collectionName: string; + position: [number]; + attributes: []; +} + +export const Nodecreation = async ( + data: IcollectionNode +): Promise => { + const { organization, projectId, position } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + isArchive: false, + }); + if (!existingProject) { + return { status: "project not found" }; + } else { + const newCollectionnode = await collectionsModel(organization).create({ + projectId: projectId, + isArchive: false, + position: position, + }); + if (!newCollectionnode) + return { status: "Collection node creation unsuccessfull" }; + else return { status: "Success", data: newCollectionnode._id }; + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +export const SetCollectionName = async ( + data: IcollectionNodeName +): Promise => { + const { + organization, + projectId, + position, + collectionNodeId, + collectionName, + } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + isArchive: false, + }); + if (!existingProject) { + return { status: "project not found" }; + } else { + const existingCollection = await collectionsModel(organization).findOne({ + projectId: projectId, + isArchive: false, + _id: collectionNodeId, + }); + if (!existingCollection) { + return { status: "Collection not found" }; + } + const collectionNameupdate = await collectionsModel( + organization + ).findOneAndUpdate( + { + projectId: projectId, + isArchive: false, + _id: collectionNodeId, + }, + { collectionNodeName: collectionName }, + { new: true } + ); + return { status: "Success" }; + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +export const addAttributes = async ( + data: IcollectionAttributes +): Promise => { + const { organization, projectId, collectionNodeId, attributes } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + isArchive: false, + }); + if (!existingProject) { + return { status: "project not found" }; + } else { + const existingCollection = await collectionsModel(organization).findOne({ + projectId: projectId, + isArchive: false, + _id: collectionNodeId, + }); + if (!existingCollection) { + return { status: "Collection not found" }; + } + const existingAttributes = existingCollection.attributes || []; + const newAttributes = attributes; + const updatedAttributesMap = new Map(); + + for (const attr of existingAttributes) { + updatedAttributesMap.set(attr.key, attr); + } + + for (const attr of newAttributes) { + if (!updatedAttributesMap.has(attr.key)) { + updatedAttributesMap.set(attr.key, attr); + } + } + + const updatedAttributes = Array.from(updatedAttributesMap.values()); + const AttributesAdded = await collectionsModel( + organization + ).findOneAndUpdate( + { + projectId: projectId, + isArchive: false, + _id: collectionNodeId, + }, + { attributes: updatedAttributes }, + { new: true } + ); + return { status: "Success" }; + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +export const GetNodesInProject = async ( + data: IcollectionNodes +): Promise => { + const { organization, projectId } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + isArchive: false, + }); + if (!existingProject) { + return { status: "project not found" }; + } else { + const collectionNodes = await collectionsModel(organization) + .find({ projectId: projectId, isArchive: false }) + .select("collectionNodeName attributes position -_id "); + if (!collectionNodes) + return { status: "No collection Nodes present", data: [] }; + else { + const formattedCollections = collectionNodes.map((collection) => ({ + position: collection.position, + collectionNodeName: collection.collectionNodeName, + attributes: collection.attributes + .filter((attr: any) => !attr.isArchive) + .map((attr: any) => { + const { isArchive, ...rest } = attr.toObject(); + return { ...rest }; + }), + })); + return { status: "Success", data: formattedCollections }; + } + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +export const UpdateAttributes = async ( + data: IAttributesEdit +): Promise => { + const { + organization, + projectId, + collectionNodeId, + attributeId, + required, + defaultValue, + unique, + index, + key, + type, + } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + isArchive: false, + }); + if (!existingProject) { + return { status: "project not found" }; + } else { + const existingCollection = await collectionsModel(organization).findOne({ + projectId: projectId, + _id: collectionNodeId, + isArchive: false, + }); + if (!existingCollection) return { status: "Collection not found" }; + + const editCollection = await collectionsModel( + organization + ).findOneAndUpdate( + { + projectId: projectId, + isArchive: false, + attributes: { + $elemMatch: { _id: new mongoose.Types.ObjectId(attributeId) }, + }, + }, + { + $set: { + "attributes.$.required": required, + "attributes.$.default": defaultValue, + "attributes.$.index": index, + "attributes.$.unique": unique, + "attributes.$.key": key, + "attributes.$.type": type, + }, + }, + { new: true } + ); + return { status: "Success" }; + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +export const DelAttributes = async ( + data: IAttributesDel +): Promise => { + const { organization, projectId, collectionNodeId, AttributeId } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + isArchive: false, + }); + if (!existingProject) { + return { status: "project not found" }; + } else { + const existingCollection = await collectionsModel(organization).findOne({ + projectId: projectId, + _id: collectionNodeId, + isArchive: false, + }); + if (!existingCollection) return { status: "Collection not found" }; + + const softDeleteAttribute = await collectionsModel( + organization + ).findOneAndUpdate( + { + projectId: projectId, + isArchive: false, + attributes: { + $elemMatch: { + _id: new mongoose.Types.ObjectId(AttributeId), + isArchive: false, + }, + }, + }, + { + $set: { + "attributes.$.isArchive": true, + }, + }, + { new: true } + ); + return { status: "Success" }; + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +export const delCollection = async ( + data: ICollectionDelete +): Promise => { + const { organization, projectId, collectionNodeId } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + isArchive: false, + }); + if (!existingProject) { + return { status: "project not found" }; + } else { + const existingCollection = await collectionsModel(organization).findOne({ + projectId: projectId, + isArchive: false, + _id: collectionNodeId, + }); + if (!existingCollection) { + return { status: "Collection not found" }; + } + const collectionSoftDelete = await collectionsModel( + organization + ).findOneAndUpdate( + { + projectId: projectId, + isArchive: false, + _id: collectionNodeId, + }, + { isArchive: true }, + { new: true } + ); + return { status: "Success" }; + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +export const GetcollectionNode = async ( + data: IcollectionNodeById +): Promise => { + const { organization, projectId, collectionNodeId } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + isArchive: false, + }); + if (!existingProject) { + return { status: "project not found" }; + } else { + const existingCollection = await collectionsModel(organization).findOne({ + projectId: projectId, + isArchive: false, + _id: collectionNodeId, + }); + if (!existingCollection) { + return { status: "Collection not found" }; + } + const formattedCollection = { + position: existingCollection.position, + collectionNodeName: existingCollection.collectionNodeName, + attributes: existingCollection.attributes + .filter((attr: any) => !attr.isArchive) + .map((attr: any) => { + const { isArchive, ...rest } = attr.toObject(); + return rest; + }), + }; + return { status: "Success", data: formattedCollection }; + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +const generateUniqueCollectionName = async ( + baseName: string, + organization: string, + projectId: string +): Promise => { + let nameToTry = baseName; + let attempt = 0; + + while (true) { + const existingCollection = await collectionsModel(organization).findOne({ + projectId, + isArchive: false, + collectionNodeName: nameToTry, + }); + if (!existingCollection) { + return nameToTry; + } + attempt++; + nameToTry = `${baseName} (duplicate${attempt > 1 ? ` ${attempt}` : ""})`; + + if (attempt > 10) { + throw new Error("Too many duplicate project name attempts"); + } + } +}; +export const DuplicateCollection = async ( + data: IDuplicateCollectionNode +): Promise => { + const { organization, projectId, position, collectionNodeId } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + isArchive: false, + }); + if (!existingProject) { + return { status: "project not found" }; + } else { + const existingCollection = await collectionsModel(organization).findOne({ + projectId: projectId, + isArchive: false, + _id: collectionNodeId, + }); + if (!existingCollection) + return { status: "CollectionId not found for duplication" }; + else { + const NewduplicateName = await generateUniqueCollectionName( + existingCollection.collectionNodeName, + organization, + projectId + ); + + const NewCollectionDuplicate = await collectionsModel( + organization + ).create({ + projectId, + isArchive: false, + position, + collectionNodeName: NewduplicateName, + }); + if (!NewCollectionDuplicate) + return { status: "Duplication unsuccessfull" }; + else { + const data = existingCollection.attributes + .filter((attr: any) => !attr.isArchive) + .map((attr: any) => { + const { isArchive, _id, ...rest } = attr.toObject(); + return rest; + }); + NewCollectionDuplicate.attributes = data; + NewCollectionDuplicate.save(); + return { status: "Success" }; + } + } + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; diff --git a/src/shared/services/edgeService.ts b/src/shared/services/edgeService.ts index 44bceef..5d9e53d 100644 --- a/src/shared/services/edgeService.ts +++ b/src/shared/services/edgeService.ts @@ -1,293 +1,293 @@ -import ProjectType from "../../shared/model/projectmodel"; -import collectionsModel from "../model/collectionModel"; -import edgeModel from "../model/edgeModel"; -interface Iresponse { - status: string; - data?: any; -} -interface IEdge { - organization: string; - projectId: string; - from: { collection_id: string, field: string }; - to: { collection_id: string }; - cardinality: string -} -interface IAllEdge { - organization: string; - projectId: string; -} -interface IEdgeDelete { - organization: string; - projectId: string; - edgeId: string; -} -interface Attribute { - key: string; - type: string; - isArchive: boolean; - - refKey?: { - collection_id: any; - fieldId: any; - }; - -} -export const edgecreation = async ( - data: IEdge -): Promise => { - const { organization, projectId, from, to, cardinality } = data; - - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - // createdBy: userName, - isArchive: false, - }); - - if (!existingProject) { - return { status: "project not found" }; - } - - const existingFromCollection = await collectionsModel(organization).findOne({ - _id: from.collection_id,isArchive: false, - }) - - if (!existingFromCollection) { - return { status: "From collection not found" }; - } - const existingToCollection = await collectionsModel(organization).findOne({ - _id: to.collection_id,isArchive: false - }) - if (!existingToCollection) { - return { status: "To collection not found" }; - } - - - const capitalizeFirst = (str: string) => { - if (!str) return str; - return str.charAt(0).toUpperCase() + str.slice(1); - }; - - const collectionName = existingFromCollection.collectionNodeName; - const fieldName = from.field; - - const newFieldKey = `${collectionName}${capitalizeFirst(fieldName)}`; - - const fromField = existingFromCollection.attributes.find( - (attr: any) => attr.key === from.field - ); - const fromFieldId = [fromField].map((attr: any) => attr?._id)[0]; - - - - const fieldType = normalizeType(fromField?.type); - - - const fieldExists = existingToCollection.attributes.some( - (attr: any) => attr.key === newFieldKey - ); - - if (!fieldExists) { - const newAttribute: any = { - key: newFieldKey, - type: fieldType, - refKey: { - collection_id: existingFromCollection._id, - fieldId: fromFieldId - } - }; - - existingToCollection.attributes.push(newAttribute); - - existingToCollection.attributes = existingToCollection.attributes.map((attr: any) => ({ - ...attr, - type: normalizeType(attr.type), - })); - - await existingToCollection.save(); - - - console.log( - `Field ${newFieldKey} (type: ${fieldType}) added to TO collection with reference to ${existingFromCollection._id}` - ); - const newEdge = { - projectId, - from: { collection_id: existingFromCollection._id, field: from.field }, - to: { collection_id: existingToCollection._id }, - cardinality, - createdAt: new Date(), - }; - const savedEdge = await edgeModel(organization).create(newEdge); - - // - return { - status: "Success", - data: savedEdge, // replace with savedEdge after model integration - }; - } - else { - console.log("Field already exists"); - return { - status: "Field already exists" - } - - - - - } - } - catch (error: unknown) { - console.log('error: ', error); - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -export const Alledges = async ( - data: IAllEdge -): Promise => { - const { organization, projectId, } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - // createdBy: userName, - isArchive: false, - }); - - if (!existingProject) { - return { status: "project not found" }; - } - const edgeDatas = await edgeModel(organization).find({isArchive: false}) - - - - if (!edgeDatas || edgeDatas.length === 0) { - return { status: "edge not found" }; - } - - return { - status: "Success", - data: edgeDatas, // replace with savedEdge after model integration - }; - - - - } catch (error: unknown) { - console.log('error: ', error); - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; -export const deleteEdge = async ( - data: IEdgeDelete -): Promise => { - const { organization, projectId, edgeId } = data; - - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - // createdBy: userName, - isArchive: false, - }); - - if (!existingProject) { - return { status: "project not found" }; - } - - const deleteEdge = await edgeModel(organization).findOneAndUpdate - ({ _id: edgeId, isArchive: false }, { - isArchive: true - }, { new: true }) - if (!deleteEdge) return { status: "Edge not found" } - const collectionDoc = await collectionsModel(organization).findOne({ - _id: deleteEdge?.to?.collection_id, isArchive: false - }); - - if (!collectionDoc ) { - return { status: "collection not found" }; - } - else { - const attributes = collectionDoc.attributes || []; - const matchedAttr = attributes.find((attr, index) => { - const refKey: any = (attr as any).refKey; - if (refKey) { - return String(refKey.collection_id) === String(deleteEdge?.from?.collection_id); - } - return false; - }); - if (matchedAttr) { - const index = attributes.indexOf(matchedAttr); - if (index > -1) { - attributes.splice(index, 1); - await collectionDoc.save(); - console.log(`Attribute at index ${index} deleted successfully.`) - } - else { - console.log('Matched attribute not found in array'); - } - - } else { - // console.log('No attribute matches the given collection_id'); - return { status: "No deleted in matched Document" } - } - - } - return {status:"Success"} - - } catch (error: unknown) { - console.log('error: ', error); - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; -const normalizeType = (type: any): string => { - if (!type) return "string"; // default - if (typeof type === "string") { - switch (type.toLowerCase()) { - case "boolean": - return "boolean"; - case "number": - return "number"; - case "string": - return "string"; - case "object": - return "object"; - case "array": - return "array"; - case "date": - return "date"; - default: - return "string"; - } - } - - // Handle cases like [Number], Boolean, Object - if (Array.isArray(type)) return "array"; - if (type === Boolean) return "boolean"; - if (type === Number) return "number"; - if (type === String) return "string"; - if (type === Object) return "object"; - - return "string"; // fallback +import ProjectType from "../../shared/model/projectmodel"; +import collectionsModel from "../model/collectionModel"; +import edgeModel from "../model/edgeModel"; +interface Iresponse { + status: string; + data?: any; +} +interface IEdge { + organization: string; + projectId: string; + from: { collection_id: string, field: string }; + to: { collection_id: string }; + cardinality: string +} +interface IAllEdge { + organization: string; + projectId: string; +} +interface IEdgeDelete { + organization: string; + projectId: string; + edgeId: string; +} +interface Attribute { + key: string; + type: string; + isArchive: boolean; + + refKey?: { + collection_id: any; + fieldId: any; + }; + +} +export const edgecreation = async ( + data: IEdge +): Promise => { + const { organization, projectId, from, to, cardinality } = data; + + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + // createdBy: userName, + isArchive: false, + }); + + if (!existingProject) { + return { status: "project not found" }; + } + + const existingFromCollection = await collectionsModel(organization).findOne({ + _id: from.collection_id,isArchive: false, + }) + + if (!existingFromCollection) { + return { status: "From collection not found" }; + } + const existingToCollection = await collectionsModel(organization).findOne({ + _id: to.collection_id,isArchive: false + }) + if (!existingToCollection) { + return { status: "To collection not found" }; + } + + + const capitalizeFirst = (str: string) => { + if (!str) return str; + return str.charAt(0).toUpperCase() + str.slice(1); + }; + + const collectionName = existingFromCollection.collectionNodeName; + const fieldName = from.field; + + const newFieldKey = `${collectionName}${capitalizeFirst(fieldName)}`; + + const fromField = existingFromCollection.attributes.find( + (attr: any) => attr.key === from.field + ); + const fromFieldId = [fromField].map((attr: any) => attr?._id)[0]; + + + + const fieldType = normalizeType(fromField?.type); + + + const fieldExists = existingToCollection.attributes.some( + (attr: any) => attr.key === newFieldKey + ); + + if (!fieldExists) { + const newAttribute: any = { + key: newFieldKey, + type: fieldType, + refKey: { + collection_id: existingFromCollection._id, + fieldId: fromFieldId + } + }; + + existingToCollection.attributes.push(newAttribute); + + existingToCollection.attributes = existingToCollection.attributes.map((attr: any) => ({ + ...attr, + type: normalizeType(attr.type), + })); + + await existingToCollection.save(); + + + console.log( + `Field ${newFieldKey} (type: ${fieldType}) added to TO collection with reference to ${existingFromCollection._id}` + ); + const newEdge = { + projectId, + from: { collection_id: existingFromCollection._id, field: from.field }, + to: { collection_id: existingToCollection._id }, + cardinality, + createdAt: new Date(), + }; + const savedEdge = await edgeModel(organization).create(newEdge); + + // + return { + status: "Success", + data: savedEdge, // replace with savedEdge after model integration + }; + } + else { + console.log("Field already exists"); + return { + status: "Field already exists" + } + + + + + } + } + catch (error: unknown) { + console.log('error: ', error); + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +export const Alledges = async ( + data: IAllEdge +): Promise => { + const { organization, projectId, } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + // createdBy: userName, + isArchive: false, + }); + + if (!existingProject) { + return { status: "project not found" }; + } + const edgeDatas = await edgeModel(organization).find({isArchive: false}) + + + + if (!edgeDatas || edgeDatas.length === 0) { + return { status: "edge not found" }; + } + + return { + status: "Success", + data: edgeDatas, // replace with savedEdge after model integration + }; + + + + } catch (error: unknown) { + console.log('error: ', error); + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; +export const deleteEdge = async ( + data: IEdgeDelete +): Promise => { + const { organization, projectId, edgeId } = data; + + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + // createdBy: userName, + isArchive: false, + }); + + if (!existingProject) { + return { status: "project not found" }; + } + + const deleteEdge = await edgeModel(organization).findOneAndUpdate + ({ _id: edgeId, isArchive: false }, { + isArchive: true + }, { new: true }) + if (!deleteEdge) return { status: "Edge not found" } + const collectionDoc = await collectionsModel(organization).findOne({ + _id: deleteEdge?.to?.collection_id, isArchive: false + }); + + if (!collectionDoc ) { + return { status: "collection not found" }; + } + else { + const attributes = collectionDoc.attributes || []; + const matchedAttr = attributes.find((attr, index) => { + const refKey: any = (attr as any).refKey; + if (refKey) { + return String(refKey.collection_id) === String(deleteEdge?.from?.collection_id); + } + return false; + }); + if (matchedAttr) { + const index = attributes.indexOf(matchedAttr); + if (index > -1) { + attributes.splice(index, 1); + await collectionDoc.save(); + console.log(`Attribute at index ${index} deleted successfully.`) + } + else { + console.log('Matched attribute not found in array'); + } + + } else { + // console.log('No attribute matches the given collection_id'); + return { status: "No deleted in matched Document" } + } + + } + return {status:"Success"} + + } catch (error: unknown) { + console.log('error: ', error); + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; +const normalizeType = (type: any): string => { + if (!type) return "string"; // default + if (typeof type === "string") { + switch (type.toLowerCase()) { + case "boolean": + return "boolean"; + case "number": + return "number"; + case "string": + return "string"; + case "object": + return "object"; + case "array": + return "array"; + case "date": + return "date"; + default: + return "string"; + } + } + + // Handle cases like [Number], Boolean, Object + if (Array.isArray(type)) return "array"; + if (type === Boolean) return "boolean"; + if (type === Number) return "number"; + if (type === String) return "string"; + if (type === Object) return "object"; + + return "string"; // fallback }; \ No newline at end of file diff --git a/src/shared/services/projectService.ts b/src/shared/services/projectService.ts index bb3165b..a3d40bd 100644 --- a/src/shared/services/projectService.ts +++ b/src/shared/services/projectService.ts @@ -1,185 +1,185 @@ -import MVCarcModel from "../../shared/model/mvcModel"; -import ProjectType from "../../shared/model/projectmodel"; -import collectionsModel from "../model/collectionModel"; -import edgeModel from "../model/edgeModel"; -interface Iresponse { - status: string; - data?: any; -} -interface IProject { - useableLanguage: string; - organization: string; - projectName: string; - userName: string; - apiType: string; - application: string; - architecture: string; - description: string; -} -interface IProjectstructure { - projectId: string; - organization: string; -} -export const projectCreationService = async ( - data: IProject -): Promise => { - const { - organization, - projectName, - useableLanguage, - description, - userName, - apiType, - application, - architecture, - } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - projectName: projectName, - createdBy: userName, - isArchive: false, - }); - if (existingProject) { - return { status: "Project Already Exists" }; - } else { - if (architecture.toLowerCase() === "mvc") { - const newProject = await ProjectType(organization).create({ - projectName, - createdBy: userName, - useableLanguage, - architecture, - apiType: apiType, - appType: application, - description, - }); - if (!newProject) return { status: "Project creation unsuccessfull" }; - const existingProjectinMVC = await MVCarcModel(organization).findOne({ - projectId: newProject._id, - isArchive: false, - }); - if (!existingProjectinMVC) { - const MVCCreation = await MVCarcModel(organization).create({ - projectId: newProject._id, - createdBy: userName, - controllers: true, - routes: true, - models: true, - services: true, - middleware: true, - utils: true, - config: true, - }); - const mvcData = MVCCreation.toObject(); - - const excludedKeys = [ - "projectId", - "_id", - "__v", - "createdBy", - "isArchive", - "folders", - ]; - const folders = Object.keys(mvcData).filter( - (key) => !excludedKeys.includes(key) && mvcData[key] === true - ); - const createdFolders = folders.map((folderName) => ({ - folderName, - createdAt: new Date(), - })); - - MVCCreation.folders.push(...createdFolders); - await MVCCreation.save(); - return { status: "Success", data: newProject._id }; - } else { - return { - status: "Already MVC architecture assigned to this projectId", - }; - } - } else { - return { status: "New architecture" }; - } - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -export const projectDatas = async (data: IProject): Promise => { - const { organization } = data; - try { - const projectDatas = await ProjectType(organization) - .findOne({ - isArchive: false, - }) - .select("-__v -isArchive -createdAt -updatedAt"); - if (!projectDatas) return { status: "No project found" }; - return { status: "Success", data: projectDatas }; - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; - -export const GetNodesInProject = async ( - data: IProjectstructure -): Promise => { - const { organization, projectId } = data; - try { - const existingProject = await ProjectType(organization).findOne({ - _id: projectId, - isArchive: false, - }); - if (!existingProject) { - return { status: "project not found" }; - } else { - const collectionNodesdata = await collectionsModel(organization) - .find({ projectId: projectId, isArchive: false }) - .select("collectionNodeName attributes position -_id "); - const edgeNodes = await edgeModel(organization) - .find({ projectId: projectId, isArchive: false }) - .select("cardinality from to"); - if(!edgeNodes) return {status:'No edge Nodes present',data:[]} - if (!collectionNodesdata) - return { status: "No collection Nodes present", data: [] }; - else { - const collectionNodes = collectionNodesdata.map((collection) => ({ - position: collection.position, - collectionNodeName: collection.collectionNodeName, - attributes: collection.attributes - .filter((attr: any) => !attr.isArchive) - .map((attr: any) => { - const { isArchive, ...rest } = attr.toObject(); - return { ...rest,edgeNodes }; - }), - - })); - return { status: "Success", data: {collectionNodes,edgeNodes} }; - } - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } - } -}; +import MVCarcModel from "../../shared/model/mvcModel"; +import ProjectType from "../../shared/model/projectmodel"; +import collectionsModel from "../model/collectionModel"; +import edgeModel from "../model/edgeModel"; +interface Iresponse { + status: string; + data?: any; +} +interface IProject { + useableLanguage: string; + organization: string; + projectName: string; + userName: string; + apiType: string; + application: string; + architecture: string; + description: string; +} +interface IProjectstructure { + projectId: string; + organization: string; +} +export const projectCreationService = async ( + data: IProject +): Promise => { + const { + organization, + projectName, + useableLanguage, + description, + userName, + apiType, + application, + architecture, + } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + projectName: projectName, + createdBy: userName, + isArchive: false, + }); + if (existingProject) { + return { status: "Project Already Exists" }; + } else { + if (architecture.toLowerCase() === "mvc") { + const newProject = await ProjectType(organization).create({ + projectName, + createdBy: userName, + useableLanguage, + architecture, + apiType: apiType, + appType: application, + description, + }); + if (!newProject) return { status: "Project creation unsuccessfull" }; + const existingProjectinMVC = await MVCarcModel(organization).findOne({ + projectId: newProject._id, + isArchive: false, + }); + if (!existingProjectinMVC) { + const MVCCreation = await MVCarcModel(organization).create({ + projectId: newProject._id, + createdBy: userName, + controllers: true, + routes: true, + models: true, + services: true, + middleware: true, + utils: true, + config: true, + }); + const mvcData = MVCCreation.toObject(); + + const excludedKeys = [ + "projectId", + "_id", + "__v", + "createdBy", + "isArchive", + "folders", + ]; + const folders = Object.keys(mvcData).filter( + (key) => !excludedKeys.includes(key) && mvcData[key] === true + ); + const createdFolders = folders.map((folderName) => ({ + folderName, + createdAt: new Date(), + })); + + MVCCreation.folders.push(...createdFolders); + await MVCCreation.save(); + return { status: "Success", data: newProject._id }; + } else { + return { + status: "Already MVC architecture assigned to this projectId", + }; + } + } else { + return { status: "New architecture" }; + } + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +export const projectDatas = async (data: IProject): Promise => { + const { organization } = data; + try { + const projectDatas = await ProjectType(organization) + .findOne({ + isArchive: false, + }) + .select("-__v -isArchive -createdAt -updatedAt"); + if (!projectDatas) return { status: "No project found" }; + return { status: "Success", data: projectDatas }; + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; + +export const GetNodesInProject = async ( + data: IProjectstructure +): Promise => { + const { organization, projectId } = data; + try { + const existingProject = await ProjectType(organization).findOne({ + _id: projectId, + isArchive: false, + }); + if (!existingProject) { + return { status: "project not found" }; + } else { + const collectionNodesdata = await collectionsModel(organization) + .find({ projectId: projectId, isArchive: false }) + .select("collectionNodeName attributes position -_id "); + const edgeNodes = await edgeModel(organization) + .find({ projectId: projectId, isArchive: false }) + .select("cardinality from to"); + if(!edgeNodes) return {status:'No edge Nodes present',data:[]} + if (!collectionNodesdata) + return { status: "No collection Nodes present", data: [] }; + else { + const collectionNodes = collectionNodesdata.map((collection) => ({ + position: collection.position, + collectionNodeName: collection.collectionNodeName, + attributes: collection.attributes + .filter((attr: any) => !attr.isArchive) + .map((attr: any) => { + const { isArchive, ...rest } = attr.toObject(); + return { ...rest,edgeNodes }; + }), + + })); + return { status: "Success", data: {collectionNodes,edgeNodes} }; + } + } + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +};