collection edge collaborated API
This commit is contained in:
@@ -29,7 +29,6 @@ export const NodeCreationController = async (
|
||||
position,
|
||||
};
|
||||
const result = await Nodecreation(data);
|
||||
console.log("result: ", result);
|
||||
|
||||
switch (result.status) {
|
||||
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 (
|
||||
req: Request,
|
||||
res: Response
|
||||
@@ -413,15 +208,9 @@ export const DuplicateNodeCollectionController = async (
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const {
|
||||
projectId,
|
||||
organization,
|
||||
collectionName,
|
||||
position,
|
||||
collectionNodeId,
|
||||
attributes,
|
||||
} = req.body;
|
||||
console.log("req.body;: ", req.body);
|
||||
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",
|
||||
@@ -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",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ to,
|
||||
cardinality
|
||||
};
|
||||
const result = await edgecreation(data);
|
||||
console.log('result: ', result);
|
||||
|
||||
switch (result.status) {
|
||||
case "project not found":
|
||||
|
||||
@@ -7,13 +7,10 @@ export const fileModelCreatecontroller = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<any> => {
|
||||
console.log("req.body: ", req.body);
|
||||
const { pathName, baseId, modelName, organization, attributes } = req.body;
|
||||
|
||||
try {
|
||||
const findBaseName = await baseType(organization).findById(baseId);
|
||||
console.log("baseId: ", baseId);
|
||||
console.log("findBaseName: ", findBaseName);
|
||||
|
||||
const attrToSchema = (attr: any) => {
|
||||
const mapType: any = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
GetNodesInProject,
|
||||
projectCreationService,
|
||||
projectDatas,
|
||||
} 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",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -13,34 +13,46 @@ import {
|
||||
|
||||
const collectionNodeRoutes = express.Router();
|
||||
//Node creation
|
||||
collectionNodeRoutes.post("/NewNode", NodeCreationController);
|
||||
collectionNodeRoutes.post("/nodes", NodeCreationController);
|
||||
//collection Added
|
||||
collectionNodeRoutes.patch("/collectionName", SetCollectionNameController);
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/collectionName",
|
||||
SetCollectionNameController
|
||||
);
|
||||
//duplicate collection
|
||||
collectionNodeRoutes.post(
|
||||
"/duplicateCollection",
|
||||
"/nodes/:collectionNodeId/duplicate",
|
||||
DuplicateNodeCollectionController
|
||||
);
|
||||
//particular collection data
|
||||
collectionNodeRoutes.get(
|
||||
"/collectionNodeById/:projectId/:collectionNodeId/:organization",
|
||||
"/nodes/:organization/:projectId/:collectionNodeId",
|
||||
CollectionDatas
|
||||
);
|
||||
//delete collection
|
||||
collectionNodeRoutes.patch(
|
||||
"/delCollection/:projectId/:collectionNodeId/:organization",
|
||||
"/nodes/:organization/:projectId/:collectionNodeId",
|
||||
DeleteCollectionsController
|
||||
);
|
||||
|
||||
//Add fields
|
||||
collectionNodeRoutes.patch("/AddAttributes", AddAttributesController);
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:collectionNodeId/attributes",
|
||||
AddAttributesController
|
||||
);
|
||||
//Collections and fiels based on the project
|
||||
collectionNodeRoutes.get(
|
||||
"/collectionNodes/:projectId/:organization",
|
||||
"/nodes/:organization/:projectId",
|
||||
NodesCollectionsBasedOnproject
|
||||
);
|
||||
//update fields
|
||||
collectionNodeRoutes.patch("/Attributeupdate", updateAttributesCollections);
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:collectionNodeId/attributes/:attributeId",
|
||||
updateAttributesCollections
|
||||
);
|
||||
//delete fields
|
||||
collectionNodeRoutes.patch("/softDelAttribute", delAttributesCollections);
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:collectionNodeId/attributes/softDelete",
|
||||
delAttributesCollections
|
||||
);
|
||||
export default collectionNodeRoutes;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import express from "express";
|
||||
import { projectCreationController } from "../controller/projectController";
|
||||
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;
|
||||
|
||||
@@ -40,7 +40,7 @@ interface IAttributesEdit {
|
||||
projectId: string;
|
||||
organization: string;
|
||||
collectionNodeId: string;
|
||||
AttributeId: string;
|
||||
attributeId: string;
|
||||
key?: string;
|
||||
type?: string;
|
||||
required?: boolean;
|
||||
@@ -179,12 +179,12 @@ export const addAttributes = async (
|
||||
const updatedAttributesMap = new Map<string, any>();
|
||||
|
||||
for (const attr of existingAttributes) {
|
||||
updatedAttributesMap.set(attr.key, attr.type.toLocaleLowerCase());
|
||||
updatedAttributesMap.set(attr.key, attr);
|
||||
}
|
||||
|
||||
for (const attr of newAttributes) {
|
||||
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,
|
||||
projectId,
|
||||
collectionNodeId,
|
||||
AttributeId,
|
||||
attributeId,
|
||||
required,
|
||||
defaultValue,
|
||||
unique,
|
||||
@@ -296,7 +296,7 @@ export const UpdateAttributes = async (
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
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 }
|
||||
);
|
||||
console.log("editCollection: ", editCollection);
|
||||
return { status: "Success" };
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
@@ -491,7 +490,6 @@ const generateUniqueCollectionName = async (
|
||||
}
|
||||
attempt++;
|
||||
nameToTry = `${baseName} (duplicate${attempt > 1 ? ` ${attempt}` : ""})`;
|
||||
console.log("nameToTry: ", nameToTry);
|
||||
|
||||
if (attempt > 10) {
|
||||
throw new Error("Too many duplicate project name attempts");
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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;
|
||||
@@ -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",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user