collection edge collaborated API

This commit is contained in:
2025-08-27 17:43:27 +05:30
parent 0cdfd21bbb
commit 38ac249f3b
8 changed files with 337 additions and 235 deletions

View File

@@ -29,7 +29,6 @@ export const NodeCreationController = async (
position, position,
}; };
const result = await Nodecreation(data); const result = await Nodecreation(data);
console.log("result: ", result);
switch (result.status) { switch (result.status) {
case "project not found": case "project not found":
@@ -115,210 +114,6 @@ export const SetCollectionNameController = async (
}); });
} }
}; };
export const AddAttributesController = async (
req: Request,
res: Response
): Promise<void> => {
try {
const { organization, projectId, collectionNodeId, 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 NodesCollectionsBasedOnproject = async (
req: Request,
res: Response
): Promise<void> => {
try {
const { projectId, organization } = req.params;
if (!organization || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const data = {
organization,
projectId,
};
const result = await GetNodesInProject(data);
switch (result.status) {
case "project not found":
res.status(200).json({
message: "project not found",
});
break;
case "No collection Nodes present":
res.status(200).json({
message: "No collection Nodes present",
Collections: result.data,
});
break;
case "Success":
res.status(200).json({ 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 updateAttributesCollections = async (
req: Request,
res: Response
): Promise<void> => {
try {
const {
organization,
projectId,
collectionNodeId,
AttributeId,
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<void> => {
try {
const { organization, projectId, collectionNodeId, 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);
console.log("result: ", result);
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",
});
}
};
export const CollectionDatas = async ( export const CollectionDatas = async (
req: Request, req: Request,
res: Response res: Response
@@ -413,15 +208,9 @@ export const DuplicateNodeCollectionController = async (
res: Response res: Response
): Promise<void> => { ): Promise<void> => {
try { try {
const { const { collectionNodeId } = req.params;
projectId, const { projectId, organization, collectionName, position, attributes } =
organization, req.body;
collectionName,
position,
collectionNodeId,
attributes,
} = req.body;
console.log("req.body;: ", req.body);
if (!organization || !projectId || !collectionNodeId) { if (!organization || !projectId || !collectionNodeId) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: "All fields are required",
@@ -463,3 +252,208 @@ export const DuplicateNodeCollectionController = async (
}); });
} }
}; };
export const NodesCollectionsBasedOnproject = async (
req: Request,
res: Response
): Promise<void> => {
try {
const { projectId, organization } = req.params;
if (!organization || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const data = {
organization,
projectId,
};
const result = await GetNodesInProject(data);
switch (result.status) {
case "project not found":
res.status(200).json({
message: "project not found",
});
break;
case "No collection Nodes present":
res.status(200).json({
message: "No collection Nodes present",
Collections: result.data,
});
break;
case "Success":
res.status(200).json({ 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<void> => {
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<void> => {
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<void> => {
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",
});
}
};

View File

@@ -20,7 +20,6 @@ to,
cardinality cardinality
}; };
const result = await edgecreation(data); const result = await edgecreation(data);
console.log('result: ', result);
switch (result.status) { switch (result.status) {
case "project not found": case "project not found":

View File

@@ -7,13 +7,10 @@ export const fileModelCreatecontroller = async (
req: Request, req: Request,
res: Response res: Response
): Promise<any> => { ): Promise<any> => {
console.log("req.body: ", req.body);
const { pathName, baseId, modelName, organization, attributes } = req.body; const { pathName, baseId, modelName, organization, attributes } = req.body;
try { try {
const findBaseName = await baseType(organization).findById(baseId); const findBaseName = await baseType(organization).findById(baseId);
console.log("baseId: ", baseId);
console.log("findBaseName: ", findBaseName);
const attrToSchema = (attr: any) => { const attrToSchema = (attr: any) => {
const mapType: any = { const mapType: any = {

View File

@@ -1,5 +1,6 @@
import { Request, Response } from "express"; import { Request, Response } from "express";
import { import {
GetNodesInProject,
projectCreationService, projectCreationService,
projectDatas, projectDatas,
} from "../../shared/services/projectService"; } from "../../shared/services/projectService";
@@ -119,3 +120,49 @@ export const getProjects = async (
}); });
} }
}; };
export const NodesCollectionsBasedOnproject = async (
req: Request,
res: Response
): Promise<void> => {
try {
const { projectId, organization } = req.params;
if (!organization || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const data = {
organization,
projectId,
};
const result = await GetNodesInProject(data);
switch (result.status) {
case "project not found":
res.status(200).json({
message: "project not found",
});
break;
case "No collection Nodes present":
res.status(200).json({
message: "No collection Nodes present",
Collections: result.data,
});
break;
case "Success":
res.status(200).json(result.data);
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
}
};

View File

@@ -13,34 +13,46 @@ import {
const collectionNodeRoutes = express.Router(); const collectionNodeRoutes = express.Router();
//Node creation //Node creation
collectionNodeRoutes.post("/NewNode", NodeCreationController); collectionNodeRoutes.post("/nodes", NodeCreationController);
//collection Added //collection Added
collectionNodeRoutes.patch("/collectionName", SetCollectionNameController); collectionNodeRoutes.patch(
"/nodes/collectionName",
SetCollectionNameController
);
//duplicate collection //duplicate collection
collectionNodeRoutes.post( collectionNodeRoutes.post(
"/duplicateCollection", "/nodes/:collectionNodeId/duplicate",
DuplicateNodeCollectionController DuplicateNodeCollectionController
); );
//particular collection data //particular collection data
collectionNodeRoutes.get( collectionNodeRoutes.get(
"/collectionNodeById/:projectId/:collectionNodeId/:organization", "/nodes/:organization/:projectId/:collectionNodeId",
CollectionDatas CollectionDatas
); );
//delete collection //delete collection
collectionNodeRoutes.patch( collectionNodeRoutes.patch(
"/delCollection/:projectId/:collectionNodeId/:organization", "/nodes/:organization/:projectId/:collectionNodeId",
DeleteCollectionsController DeleteCollectionsController
); );
//Add fields //Add fields
collectionNodeRoutes.patch("/AddAttributes", AddAttributesController); collectionNodeRoutes.patch(
"/nodes/:collectionNodeId/attributes",
AddAttributesController
);
//Collections and fiels based on the project //Collections and fiels based on the project
collectionNodeRoutes.get( collectionNodeRoutes.get(
"/collectionNodes/:projectId/:organization", "/nodes/:organization/:projectId",
NodesCollectionsBasedOnproject NodesCollectionsBasedOnproject
); );
//update fields //update fields
collectionNodeRoutes.patch("/Attributeupdate", updateAttributesCollections); collectionNodeRoutes.patch(
"/nodes/:collectionNodeId/attributes/:attributeId",
updateAttributesCollections
);
//delete fields //delete fields
collectionNodeRoutes.patch("/softDelAttribute", delAttributesCollections); collectionNodeRoutes.patch(
"/nodes/:collectionNodeId/attributes/softDelete",
delAttributesCollections
);
export default collectionNodeRoutes; export default collectionNodeRoutes;

View File

@@ -1,8 +1,12 @@
import express from "express"; import express from "express";
import { projectCreationController } from "../controller/projectController"; import { NodesCollectionsBasedOnproject, projectCreationController } from "../controller/projectController";
const projectRoutes = express.Router(); const projectRoutes = express.Router();
projectRoutes.post("/Newproject", projectCreationController); projectRoutes.post("/Newproject", projectCreationController);
projectRoutes.get(
"/nodes/:organization/:projectId",
NodesCollectionsBasedOnproject
);
// appRoutes.post("/createfileModel", fileModelCreatecontroller); // appRoutes.post("/createfileModel", fileModelCreatecontroller);
export default projectRoutes; export default projectRoutes;

View File

@@ -40,7 +40,7 @@ interface IAttributesEdit {
projectId: string; projectId: string;
organization: string; organization: string;
collectionNodeId: string; collectionNodeId: string;
AttributeId: string; attributeId: string;
key?: string; key?: string;
type?: string; type?: string;
required?: boolean; required?: boolean;
@@ -179,12 +179,12 @@ export const addAttributes = async (
const updatedAttributesMap = new Map<string, any>(); const updatedAttributesMap = new Map<string, any>();
for (const attr of existingAttributes) { for (const attr of existingAttributes) {
updatedAttributesMap.set(attr.key, attr.type.toLocaleLowerCase()); updatedAttributesMap.set(attr.key, attr);
} }
for (const attr of newAttributes) { for (const attr of newAttributes) {
if (!updatedAttributesMap.has(attr.key)) { if (!updatedAttributesMap.has(attr.key)) {
updatedAttributesMap.set(attr.key, attr.type.toLocaleLowerCase()); updatedAttributesMap.set(attr.key, attr);
} }
} }
@@ -266,7 +266,7 @@ export const UpdateAttributes = async (
organization, organization,
projectId, projectId,
collectionNodeId, collectionNodeId,
AttributeId, attributeId,
required, required,
defaultValue, defaultValue,
unique, unique,
@@ -296,7 +296,7 @@ export const UpdateAttributes = async (
projectId: projectId, projectId: projectId,
isArchive: false, isArchive: false,
attributes: { attributes: {
$elemMatch: { _id: new mongoose.Types.ObjectId(AttributeId) }, $elemMatch: { _id: new mongoose.Types.ObjectId(attributeId) },
}, },
}, },
{ {
@@ -311,7 +311,6 @@ export const UpdateAttributes = async (
}, },
{ new: true } { new: true }
); );
console.log("editCollection: ", editCollection);
return { status: "Success" }; return { status: "Success" };
} }
} catch (error: unknown) { } catch (error: unknown) {
@@ -491,7 +490,6 @@ const generateUniqueCollectionName = async (
} }
attempt++; attempt++;
nameToTry = `${baseName} (duplicate${attempt > 1 ? ` ${attempt}` : ""})`; nameToTry = `${baseName} (duplicate${attempt > 1 ? ` ${attempt}` : ""})`;
console.log("nameToTry: ", nameToTry);
if (attempt > 10) { if (attempt > 10) {
throw new Error("Too many duplicate project name attempts"); throw new Error("Too many duplicate project name attempts");

View File

@@ -1,5 +1,7 @@
import MVCarcModel from "../../shared/model/mvcModel"; import MVCarcModel from "../../shared/model/mvcModel";
import ProjectType from "../../shared/model/projectmodel"; import ProjectType from "../../shared/model/projectmodel";
import collectionsModel from "../model/collectionModel";
import edgeModel from "../model/edgeModel";
interface Iresponse { interface Iresponse {
status: string; status: string;
data?: any; data?: any;
@@ -132,3 +134,52 @@ export const projectDatas = async (data: IProject): Promise<Iresponse> => {
} }
} }
}; };
export const GetNodesInProject = async (
data: IProjectstructure
): Promise<Iresponse> => {
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",
};
}
}
};