collection position zoom updated

This commit is contained in:
2025-10-29 10:51:04 +05:30
parent e65bb2b480
commit 3ae01f4dde
9 changed files with 163 additions and 552 deletions

View File

@@ -14,6 +14,8 @@ import {
GetcollectionGraphicData, GetcollectionGraphicData,
} from "../../shared/services/collectionService"; } from "../../shared/services/collectionService";
import { AuthenticatedRequest } from "../../shared/utils/token"; import { AuthenticatedRequest } from "../../shared/utils/token";
// - working
export const NodeCreationController = async ( export const NodeCreationController = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response
@@ -92,6 +94,7 @@ export const NodeCreationController = async (
} }
}; };
// - working
//casting error handled and missing fields handling updated for testing //casting error handled and missing fields handling updated for testing
export const updateCollectionController = async ( export const updateCollectionController = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
@@ -306,7 +309,7 @@ export const graphicDatas = async (
}); });
} }
}; };
// - working
export const DeleteCollectionsController = async ( export const DeleteCollectionsController = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response
@@ -494,6 +497,7 @@ export const NodesCollectionsBasedOnproject = async (
} }
}; };
// - working
export const AddAttributesController = async ( export const AddAttributesController = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response
@@ -569,7 +573,7 @@ export const AddAttributesController = async (
}); });
} }
}; };
// - working
export const updateAttributesCollections = async ( export const updateAttributesCollections = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response
@@ -602,6 +606,7 @@ export const updateAttributesCollections = async (
collectionNodeId, collectionNodeId,
attributes, attributes,
}; };
console.log("data: ", data);
const result = await UpdateAttributes(data); const result = await UpdateAttributes(data);
console.log("result:d ", result); console.log("result:d ", result);
@@ -634,7 +639,7 @@ export const updateAttributesCollections = async (
}); });
} }
}; };
// - working
export const delAttributesCollections = async ( export const delAttributesCollections = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response

View File

@@ -5,6 +5,8 @@ import {
edgecreation, edgecreation,
} from "../../shared/services/edgeService"; } from "../../shared/services/edgeService";
import { AuthenticatedRequest } from "../../shared/utils/token"; import { AuthenticatedRequest } from "../../shared/utils/token";
// - working
export const edgeCreationController = async ( export const edgeCreationController = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response
@@ -149,6 +151,8 @@ export const allEdgesController = async (
}); });
} }
}; };
// - working
export const deleteEdgesController = async ( export const deleteEdgesController = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response

View File

@@ -9,7 +9,7 @@ import {
ViewProjectService, ViewProjectService,
} from "../../shared/services/projectService"; } from "../../shared/services/projectService";
import { AuthenticatedRequest } from "../../shared/utils/token"; import { AuthenticatedRequest } from "../../shared/utils/token";
// - working
export const projectCreationController = async ( export const projectCreationController = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response
@@ -187,6 +187,9 @@ export const NodesCollectionsBasedOnproject = async (
message: "User not found", message: "User not found",
}); });
break; break;
case "Invalid ID":
res.status(400).json({ message: result.data || "Invalid ID provided" });
break;
case "No collection Nodes present": case "No collection Nodes present":
res.status(200).json({ res.status(200).json({
message: "No collection Nodes present", message: "No collection Nodes present",
@@ -250,6 +253,9 @@ export const accessAproject = async (
projectDatas: result.data, projectDatas: result.data,
}); });
break; break;
case "Invalid ID":
res.status(400).json({ message: result.data || "Invalid ID provided" });
break;
default: default:
res.status(500).json({ res.status(500).json({
message: "Internal server error", message: "Internal server error",
@@ -262,7 +268,7 @@ export const accessAproject = async (
}); });
} }
}; };
// - working
export const deleteProjectController = async ( export const deleteProjectController = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response
@@ -304,6 +310,9 @@ export const deleteProjectController = async (
.status(200) .status(200)
.json({ message: "No access granted to delete this project" }); .json({ message: "No access granted to delete this project" });
break; break;
case "Invalid ID":
res.status(400).json({ message: result.data || "Invalid ID provided" });
break;
case "Project Delete unsuccessfull": case "Project Delete unsuccessfull":
res.status(200).json({ message: "Project Delete unsuccessfull" }); res.status(200).json({ message: "Project Delete unsuccessfull" });
break; break;
@@ -324,7 +333,7 @@ export const deleteProjectController = async (
}); });
} }
}; };
// - working
export const updateProjectController = async ( export const updateProjectController = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response
@@ -373,6 +382,14 @@ export const updateProjectController = async (
case "Project not found": case "Project not found":
res.status(404).json({ message: "Project not found" }); res.status(404).json({ message: "Project not found" });
break; break;
case "No access granted to delete this project":
res
.status(200)
.json({ message: "No access granted to update this project" });
break;
case "Invalid ID":
res.status(400).json({ message: result.data || "Invalid ID provided" });
break;
case "Project update unsuccessfull": case "Project update unsuccessfull":
res.status(200).json({ message: "Project update unsuccessfull" }); res.status(200).json({ message: "Project update unsuccessfull" });
break; break;
@@ -393,7 +410,7 @@ export const updateProjectController = async (
}); });
} }
}; };
// - working
export const projectClearController = async ( export const projectClearController = async (
req: AuthenticatedRequest, req: AuthenticatedRequest,
res: Response res: Response
@@ -439,6 +456,9 @@ export const projectClearController = async (
message: "Datas cleared successfully", message: "Datas cleared successfully",
}); });
break; break;
case "Invalid ID":
res.status(400).json({ message: result.data || "Invalid ID provided" });
break;
case "Validation Error": case "Validation Error":
res.status(400).json({ message: result.data || "Validation Error" }); res.status(400).json({ message: result.data || "Validation Error" });
break; break;

View File

@@ -18,7 +18,7 @@ import authorizedRoles from "../../shared/middleware/rbacMiddleware";
const collectionNodeRoutes = express.Router(); const collectionNodeRoutes = express.Router();
//Node creation //Node creation - working
collectionNodeRoutes.post( collectionNodeRoutes.post(
"/node/save", "/node/save",
tokenValidator, tokenValidator,
@@ -26,7 +26,7 @@ collectionNodeRoutes.post(
NodeCreationController NodeCreationController
); );
//collection update //collection update - working
collectionNodeRoutes.patch( collectionNodeRoutes.patch(
"/nodes/update/:projectId/:collectionNodeId", "/nodes/update/:projectId/:collectionNodeId",
tokenValidator, tokenValidator,
@@ -50,7 +50,7 @@ collectionNodeRoutes.get(
CollectionDatas CollectionDatas
); );
//delete collection //delete collection - working
collectionNodeRoutes.patch( collectionNodeRoutes.patch(
"/nodes/:projectId/:collectionNodeId", "/nodes/:projectId/:collectionNodeId",
tokenValidator, tokenValidator,
@@ -58,7 +58,7 @@ collectionNodeRoutes.patch(
DeleteCollectionsController DeleteCollectionsController
); );
//Add fields to the collection node //Add fields to the collection node - working
collectionNodeRoutes.patch( collectionNodeRoutes.patch(
"/node/attributes", "/node/attributes",
tokenValidator, tokenValidator,
@@ -74,7 +74,7 @@ collectionNodeRoutes.get(
NodesCollectionsBasedOnproject NodesCollectionsBasedOnproject
); );
//update fields //update fields - working
collectionNodeRoutes.patch( collectionNodeRoutes.patch(
"/nodesfield/attribute/:collectionNodeId", "/nodesfield/attribute/:collectionNodeId",
tokenValidator, tokenValidator,
@@ -82,7 +82,7 @@ collectionNodeRoutes.patch(
updateAttributesCollections updateAttributesCollections
); );
//delete fields //delete fields - working
collectionNodeRoutes.patch( collectionNodeRoutes.patch(
"/nodes/:collectionNodeId/attributes/softdelete", "/nodes/:collectionNodeId/attributes/softdelete",
tokenValidator, tokenValidator,

View File

@@ -7,13 +7,15 @@ import {
import { tokenValidator } from "../../shared/utils/token"; import { tokenValidator } from "../../shared/utils/token";
import authorizedRoles from "../../shared/middleware/rbacMiddleware"; import authorizedRoles from "../../shared/middleware/rbacMiddleware";
const edgeRoutes = express.Router(); const edgeRoutes = express.Router();
// - working
edgeRoutes.post( edgeRoutes.post(
"/edge/save", "/edge/save",
tokenValidator, tokenValidator,
authorizedRoles("Admin", "Editor", "Viewer"), authorizedRoles("Admin", "Editor", "Viewer"),
edgeCreationController edgeCreationController
); );
// - working
edgeRoutes.patch( edgeRoutes.patch(
"/edge/:projectId/:edgeId", "/edge/:projectId/:edgeId",
tokenValidator, tokenValidator,

View File

@@ -14,7 +14,7 @@ import { tokenValidator } from "../../shared/utils/token";
const projectRoutes = express.Router(); const projectRoutes = express.Router();
//project save //project save - working
projectRoutes.post( projectRoutes.post(
"/project/save", "/project/save",
tokenValidator, tokenValidator,
@@ -46,14 +46,14 @@ projectRoutes.get(
accessAproject accessAproject
); );
//delete Project //delete Project - working
projectRoutes.patch( projectRoutes.patch(
"/project/deleteproject/:projectId", "/project/deleteproject/:projectId",
tokenValidator, tokenValidator,
authorizedRoles("Admin", "Editor"), authorizedRoles("Admin", "Editor"),
deleteProjectController deleteProjectController
); );
// - working
projectRoutes.patch( projectRoutes.patch(
"/project/updateproject", "/project/updateproject",
tokenValidator, tokenValidator,
@@ -61,7 +61,7 @@ projectRoutes.patch(
updateProjectController updateProjectController
); );
//clear Project //clear Project - working
projectRoutes.patch( projectRoutes.patch(
"/project/:projectId/clearAll", "/project/:projectId/clearAll",
tokenValidator, tokenValidator,

View File

@@ -51,6 +51,7 @@ export interface ICollectionNode extends Document {
position: { position: {
x: number; x: number;
y: number; y: number;
zoom: number;
}; };
} }
const attributeSchema = new Schema<IAttributes>({ const attributeSchema = new Schema<IAttributes>({
@@ -122,6 +123,7 @@ const collectionSchema: Schema<ICollectionNode> = new Schema(
position: { position: {
x: { type: Number }, x: { type: Number },
y: { type: Number }, y: { type: Number },
zoom: { type: Number },
}, },
lineThickness: { type: Number }, lineThickness: { type: Number },
fontName: { type: String }, fontName: { type: String },

View File

@@ -13,7 +13,11 @@ interface IcollectionNode {
collectionName: string; collectionName: string;
type: string; type: string;
organization: string; organization: string;
position: [number]; position: {
x: number;
y: number;
zoom: number;
};
} }
interface IAttribute { interface IAttribute {
key: string; key: string;
@@ -34,7 +38,11 @@ interface IcollectionNodeName {
lineType?: string; lineType?: string;
borderThickness?: number; borderThickness?: number;
cornerRadius?: number; cornerRadius?: number;
position?: [number]; position?: {
x: number;
y: number;
zoom: number;
};
} }
interface IcollectionAttributes { interface IcollectionAttributes {
projectId: string; projectId: string;
@@ -92,15 +100,6 @@ interface IAttributesUpdate {
organization: string; organization: string;
collectionNodeId: string; collectionNodeId: string;
attributes: IupdateChange[]; attributes: IupdateChange[];
// fieldId: string;
// key?: string;
// type?: string;
// primary: boolean;
// required?: boolean;
// defaultValue?: any;
// unique?: boolean;
// index?: boolean;
// isIdentifier?: boolean;
} }
interface IAttributesDel { interface IAttributesDel {
projectId: string; projectId: string;
@@ -121,7 +120,11 @@ interface IDuplicateCollectionNode {
collectionNodeId: string; collectionNodeId: string;
organization: string; organization: string;
collectionName: string; collectionName: string;
position: [number]; position: {
x: number;
y: number;
zoom: number;
};
attributes: []; attributes: [];
} }
interface IDuplicateattributes { interface IDuplicateattributes {
@@ -131,6 +134,8 @@ interface IDuplicateattributes {
organization: string; organization: string;
attrKey: string; attrKey: string;
} }
// - working
export const Nodecreation = async ( export const Nodecreation = async (
data: IcollectionNode data: IcollectionNode
): Promise<Iresponse> => { ): Promise<Iresponse> => {
@@ -161,10 +166,6 @@ export const Nodecreation = async (
const newAttributes = attributes; const newAttributes = attributes;
const updatedAttributesMap = new Map<string, any>(); const updatedAttributesMap = new Map<string, any>();
// for (const attr of existingAttributes) {
// 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); updatedAttributesMap.set(attr.key, attr);
@@ -201,7 +202,7 @@ export const Nodecreation = async (
} }
} }
}; };
// - working
export const updatecollection = async ( export const updatecollection = async (
data: IcollectionNodeName data: IcollectionNodeName
): Promise<Iresponse> => { ): Promise<Iresponse> => {
@@ -292,129 +293,6 @@ export const updatecollection = async (
} }
}; };
// export const addAttributes = async (
// data: IcollectionAttributes
// ): Promise<Iresponse> => {
// const { organization, projectId, userId, collectionNodeId, attributes } =
// data;
// console.log('data: ', data);
// try {
// const ExistingUser = await userModel(organization).findOne({
// _id: userId,
// isArchive: false,
// });
// if (!ExistingUser) return { status: "User not found" };
// 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<string, any>();
// 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 }
// );
// if (AttributesAdded) {
// for (const attr of AttributesAdded.attributes) {
// console.log('attr: ', attr);
// if (attr.type === "Object") {
// const existingsubcollection = await collectionsModel(
// organization
// ).findOne({
// projectId: projectId,
// parentCollectionNodeId: collectionNodeId,
// attributeparentId: (attr as any)._id,
// isArchive: false,
// });
// console.log("existingsubcollection: ", existingsubcollection);
// if (!existingsubcollection) {
// const newCollection = await collectionsModel(organization).create(
// {
// type: "objectNode",
// isArchive: false,
// projectId: projectId,
// collectionName: attr.key,
// parentCollectionNodeId: collectionNodeId,
// attributeparentId: (attr as any)._id,
// attributes: [],
// // position: [0, 0, 0],
// }
// );
// AttributesAdded.isSubCollection = true;
// await AttributesAdded.save();
// } else {
// return {
// status: "Subcollection already added for the object data",
// };
// }
// }
// }
// await AttributesAdded.save();
// }
// const newlyAddedAttributes = updatedAttributes.filter(
// (attr) => !existingAttributes.some((exAttr) => exAttr.key === attr.key)
// );
// const addedFieldIds = newlyAddedAttributes.map((attr) => attr._id);
// console.log("addedFieldIds: ", addedFieldIds);
// //how to send the added fieldId in response
// return { status: "Success" };
// }
// } catch (error: unknown) {
// if (error instanceof mongoose.Error.CastError) {
// return {
// status: "Invalid ObjectId",
// data: error.message,
// };
// }
// if (error instanceof mongoose.Error.ValidationError) {
// return { status: "Validation Error", data: error.message };
// }
// if (error instanceof Error) {
// return {
// status: error.message,
// };
// } else {
// return {
// status: "An unexpected error occurred",
// };
// }
// }
// };
//both collections and edges in projects
export const GetNodesInProject = async ( export const GetNodesInProject = async (
data: IcollectionNodes data: IcollectionNodes
): Promise<Iresponse> => { ): Promise<Iresponse> => {
@@ -462,16 +340,19 @@ export const GetNodesInProject = async (
); );
if (refAttribute) { if (refAttribute) {
// targetFieldKey = refAttribute.key;
targetFieldKey = refAttribute.key; targetFieldKey = refAttribute.key;
} }
} }
return { return {
edgeId: e._id, edgeId: e._id,
id: `e_source-${e.from.collection_id}-${e.from.collection_id}_${targetFieldKey}`,
source: e.from.collection_id, source: e.from.collection_id,
sourceHandle: e.from.field, sourceHandle: `source-${e.from.collection_id}-${e.from.field}`,
target: e.to.collection_id, target: e.to.collection_id,
targetHandle: targetFieldKey || e.to.collection_id, targetHandle: `target-${e.to.collection_id}-${targetFieldKey}`,
// targetHandle: targetFieldKey || e.to.collection_id,
}; };
}) })
); );
@@ -517,6 +398,7 @@ export const GetNodesInProject = async (
} }
return baseData; return baseData;
}); });
console.log("filteredEdges: ", filteredEdges);
const finalResult = { const finalResult = {
nodes: formattedCollections, nodes: formattedCollections,
edges: filteredEdges, edges: filteredEdges,
@@ -536,7 +418,7 @@ export const GetNodesInProject = async (
} }
} }
}; };
// - working
export const UpdateAttributes = async ( export const UpdateAttributes = async (
// data: IAttributesEdit // data: IAttributesEdit
data: IAttributesUpdate data: IAttributesUpdate
@@ -597,7 +479,7 @@ export const UpdateAttributes = async (
parentCollectionNodeId: collectionNodeId, parentCollectionNodeId: collectionNodeId,
attributeparentId: fieldId, attributeparentId: fieldId,
attributes: [], attributes: [],
// position: [0, 0, 0], position: { x: 0, y: 0, zoom: 2 },
}); });
existingCollection.isSubCollection = true; existingCollection.isSubCollection = true;
await existingCollection.save(); await existingCollection.save();
@@ -631,6 +513,28 @@ export const UpdateAttributes = async (
}, },
{ new: true } { new: true }
); );
// if (editCollection) {
// // find all collections that reference this fieldId
// const foreignCollections = await collectionsModel(organization).find({
// projectId: projectId,
// isArchive: false,
// "attributes.refKey.fieldId": new mongoose.Types.ObjectId(fieldId),
// });
// for (const foreign of foreignCollections) {
// for (const fattr of foreign.attributes) {
// if (
// fattr.refKey &&
// (fattr.refKey as any).fieldId?.toString() === fieldId.toString()
// ) {
// // update key name to follow "collectionName_fieldKey"
// fattr.key = `${editCollection.collectionName}_${attr.key}`;
// // }
// }
// await foreign.save();
// }
// }
// }
} }
return { status: "Success" }; return { status: "Success" };
} }
@@ -647,267 +551,7 @@ export const UpdateAttributes = async (
} }
}; };
// export const DelAttributes = async ( // - working
// data: IAttributesDel
// ): Promise<Iresponse> => {
// const { organization, userId, projectId, collectionNodeId, fieldId } = data;
// try {
// const ExistingUser = await userModel(organization).findOne({
// _id: userId,
// isArchive: false,
// });
// if (!ExistingUser) return { status: "User not found" };
// 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).findOne(
// {
// projectId: projectId,
// isArchive: false,
// attributes: {
// $elemMatch: {
// _id: new mongoose.Types.ObjectId(fieldId),
// isArchive: false,
// },
// },
// },
// {
// "attributes.$": 1,
// }
// );
// if (softDeleteAttribute?.attributes[0].type === "Object") {
// console.log("object type ");
// const mainCollectionNode = await collectionsModel(
// organization
// ).findOneAndUpdate(
// {
// projectId: projectId,
// isArchive: false,
// attributes: {
// $elemMatch: {
// _id: new mongoose.Types.ObjectId(fieldId),
// isArchive: false,
// },
// },
// },
// {
// $set: {
// "attributes.$.isArchive": true,
// },
// },
// { new: true }
// );
// if (mainCollectionNode) {
// const objectNodeCollection = await collectionsModel(
// organization
// ).findOneAndUpdate(
// {
// projectId,
// parentCollectionNodeId: collectionNodeId,
// attributeparentId: fieldId,
// isArchive: false,
// },
// { isArchive: true }
// );
// }
// const fieldnamefind = await collectionsModel(organization).findOne(
// {
// projectId: projectId,
// isArchive: false,
// _id: collectionNodeId,
// "attributes._id": new mongoose.Types.ObjectId(fieldId),
// },
// {
// "attributes.$": 1,
// }
// );
// const matchingEdgeData = await edgeModel(organization).findOne({
// "from.collection_id": softDeleteAttribute?._id,
// "from.field": fieldnamefind?.attributes[0].key,
// projectId,
// isArchive: false,
// });
// if (matchingEdgeData) {
// const deleteEdge = await edgeModel(organization).findOneAndUpdate(
// {
// "from.collection_id": softDeleteAttribute?._id,
// "from.field": fieldnamefind?.attributes[0].key,
// projectId,
// isArchive: false,
// },
// { isArchive: true },
// { new: true }
// );
// if (deleteEdge?.to?.collection_id) {
// await collectionsModel(organization).updateOne(
// {
// _id: deleteEdge.to.collection_id,
// projectId,
// isArchive: false,
// },
// {
// $pull: {
// attributes: {
// "refKey.fieldId": new mongoose.Types.ObjectId(fieldId),
// },
// },
// }
// );
// }
// }
// } else if (softDeleteAttribute?.attributes[0].type !== "Object") {
// console.log("string format ");
// const mainCollectionNode = await collectionsModel(
// organization
// ).findOneAndUpdate(
// {
// projectId: projectId,
// isArchive: false,
// attributes: {
// $elemMatch: {
// _id: new mongoose.Types.ObjectId(fieldId),
// isArchive: false,
// },
// },
// },
// {
// $set: {
// "attributes.$.isArchive": true,
// },
// },
// { new: true }
// );
// const fieldnamefind = await collectionsModel(organization).findOne(
// {
// projectId: projectId,
// isArchive: false,
// _id: collectionNodeId,
// "attributes._id": new mongoose.Types.ObjectId(fieldId),
// },
// {
// "attributes.$": 1,
// }
// );
// const matchingEdgeData = await edgeModel(organization).findOne({
// "from.collection_id": softDeleteAttribute?._id,
// "from.field": fieldnamefind?.attributes[0].key,
// projectId,
// isArchive: false,
// });
// if (matchingEdgeData) {
// const deleteEdge = await edgeModel(organization).findOneAndUpdate(
// {
// "from.collection_id": softDeleteAttribute?._id,
// "from.field": fieldnamefind?.attributes[0].key,
// projectId,
// isArchive: false,
// },
// { isArchive: true },
// { new: true }
// );
// if (deleteEdge?.to?.collection_id) {
// await collectionsModel(organization).updateOne(
// {
// _id: deleteEdge.to.collection_id,
// projectId,
// isArchive: false,
// },
// {
// $pull: {
// attributes: {
// "refKey.fieldId": new mongoose.Types.ObjectId(fieldId),
// },
// },
// }
// );
// }
// }
// }
// // ===
// else {
// console.log("edge");
// const fieldnamefind = await collectionsModel(organization).findOne(
// {
// projectId: projectId,
// isArchive: false,
// _id: collectionNodeId,
// "attributes._id": new mongoose.Types.ObjectId(fieldId),
// },
// {
// "attributes.$": 1,
// }
// );
// const matchingEdgeData = await edgeModel(organization).findOneAndUpdate(
// {
// from: {
// collection_id: softDeleteAttribute?._id,
// field: fieldnamefind?.attributes[0].key,
// },
// projectId,
// isArchive: false,
// },
// { isArchive: true },
// { new: true }
// );
// if (matchingEdgeData?.to?.collection_id) {
// await collectionsModel(organization).updateOne(
// {
// _id: matchingEdgeData.to.collection_id,
// projectId,
// isArchive: false,
// },
// {
// $pull: {
// attributes: {
// "refKey.fieldId": new mongoose.Types.ObjectId(fieldId),
// },
// },
// }
// );
// }
// }
// // ======
// // if (connectionField) {
// // if (
// // connectionField.attributes.includes(refkey.collection_id) ===
// // softDeleteAttribute?._id &&
// // connectionField.attributes.refkey.fieldId === fieldId
// // ) {
// // connectionField.attributes.refkey(delete)
// // }
// // }
// 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 ( export const delCollection = async (
data: ICollectionDelete data: ICollectionDelete
): Promise<Iresponse> => { ): Promise<Iresponse> => {
@@ -1284,124 +928,12 @@ export const GetcollectionLists = async (
} }
}; };
// export const addAttributes = async ( // - working
// data: IcollectionAttributes
// ): Promise<Iresponse> => {
// const { organization, projectId, userId, collectionNodeId, attributes } =
// data;
// try {
// const ExistingUser = await userModel(organization).findOne({
// _id: userId,
// isArchive: false,
// });
// if (!ExistingUser) return { status: "User not found" };
// const existingProject = await ProjectType(organization).findOne({
// _id: projectId,
// isArchive: false,
// });
// if (!existingProject) return { status: "project not found" };
// const existingCollection = await collectionsModel(organization).findOne({
// projectId,
// isArchive: false,
// _id: collectionNodeId,
// });
// if (!existingCollection) return { status: "Collection not found" };
// const existingAttributes = existingCollection.attributes || [];
// const updatedAttributesMap = new Map<string, any>();
// // Keep old attributes
// // for (const attr of existingAttributes) {
// // updatedAttributesMap.set(attr.key, attr);
// // console.log('updatedAttributesMap: old', updatedAttributesMap);
// // }
// for (const attr of existingAttributes) {
// if (!attr.isArchive) {
// updatedAttributesMap.set(attr.key, attr);
// }
// }
// // Add new attributes
// for (const attr of attributes) {
// if (!updatedAttributesMap.has(attr.key)) {
// updatedAttributesMap.set(attr.key, attr);
// console.log("updatedAttributesMap: ", updatedAttributesMap);
// }
// }
// const updatedAttributes = Array.from(updatedAttributesMap.values());
// // Update collection with new attributes
// const AttributesAdded = await collectionsModel(
// organization
// ).findOneAndUpdate(
// { projectId, isArchive: false, _id: collectionNodeId },
// { attributes: updatedAttributes },
// { new: true }
// );
// if (!AttributesAdded) return { status: "Failed to add attributes" };
// // Create subcollections for Object type attributes if not already
// for (const attr of AttributesAdded.attributes) {
// if (attr.type === "Object") {
// const existingsubcollection = await collectionsModel(
// organization
// ).findOne({
// projectId,
// parentCollectionNodeId: collectionNodeId,
// attributeparentId: (attr as any)._id,
// isArchive: false,
// });
// if (!existingsubcollection) {
// await collectionsModel(organization).create({
// type: "objectNode",
// isArchive: false,
// projectId,
// collectionName: attr.key,
// parentCollectionNodeId: collectionNodeId,
// attributeparentId: (attr as any)._id,
// attributes: [],
// });
// AttributesAdded.isSubCollection = true;
// }
// }
// }
// await AttributesAdded.save();
// const newlyAddedAttributes = AttributesAdded.attributes.filter(
// (attr) => !existingAttributes.some((exAttr) => exAttr.key === attr.key)
// );
// const addedFieldIds = newlyAddedAttributes.map((attr) => (attr as any)._id);
// // const addedFieldIds = newlyAddedAttributes
// // .map((attr) => (attr as any)._id.toString())
// // .join(",");
// console.log("addedFieldIds: ", addedFieldIds);
// return {
// status: "Success",
// data: addedFieldIds,
// };
// } catch (error: unknown) {
// if (error instanceof mongoose.Error.CastError)
// return { status: "Invalid ObjectId", data: error.message };
// if (error instanceof mongoose.Error.ValidationError)
// return { status: "Validation Error", data: error.message };
// if (error instanceof Error) return { status: error.message };
// return { status: "An unexpected error occurred" };
// }
// };
export const DelAttributes = async ( export const DelAttributes = async (
data: IAttributesDel data: IAttributesDel
): Promise<Iresponse> => { ): Promise<Iresponse> => {
const { organization, userId, projectId, collectionNodeId, fieldId } = data; const { organization, userId, projectId, collectionNodeId, fieldId } = data;
console.log('data: ', data); console.log("data: ", data);
try { try {
const existingUser = await userModel(organization).findOne({ const existingUser = await userModel(organization).findOne({
@@ -1422,7 +954,7 @@ export const DelAttributes = async (
isArchive: false, isArchive: false,
"attributes._id": new mongoose.Types.ObjectId(fieldId), "attributes._id": new mongoose.Types.ObjectId(fieldId),
}); });
console.log('existingCollection: ', existingCollection); console.log("existingCollection: ", existingCollection);
if (!existingCollection) return { status: "Collection not found" }; if (!existingCollection) return { status: "Collection not found" };
const attribute = existingCollection.attributes.find( const attribute = existingCollection.attributes.find(
@@ -1480,7 +1012,7 @@ export const DelAttributes = async (
return { status: "An unexpected error occurred" }; return { status: "An unexpected error occurred" };
} }
}; };
// - working
export const addAttributes = async ( export const addAttributes = async (
data: IcollectionAttributes data: IcollectionAttributes
): Promise<Iresponse> => { ): Promise<Iresponse> => {

View File

@@ -8,6 +8,7 @@ import userDataModel from "../model/userDataModel";
import userModel from "../model/userModel"; import userModel from "../model/userModel";
import versionModel from "../model/versionModel"; import versionModel from "../model/versionModel";
import groupModel from "../model/groupModel"; import groupModel from "../model/groupModel";
import mongoose from "mongoose";
interface Iresponse { interface Iresponse {
status: string; status: string;
data?: any; data?: any;
@@ -62,7 +63,7 @@ export const previousVersion = async (
return result; return result;
}; };
// - working
export const projectCreationService = async ( export const projectCreationService = async (
data: IProject data: IProject
): Promise<Iresponse> => { ): Promise<Iresponse> => {
@@ -224,11 +225,32 @@ export const projectDatas = async (data: IgetProject): Promise<Iresponse> => {
.populate({ .populate({
path: "createdBy", path: "createdBy",
model: userModel(organization), model: userModel(organization),
select: "userName", select: "userName profilePicture",
}) })
.skip(skipdata) .skip(skipdata)
.limit(limitdata); .limit(limitdata);
console.log('projectDatas: ', projectDatas);
if (!projectDatas) return { status: "No project found" }; if (!projectDatas) return { status: "No project found" };
// const formattedProjects = projectDatas.map((proj: any) => {
// const creator = proj.createdBy;
// const profile =
// creator?.profilePicture ||
// (creator?.userName ? creator.userName.charAt(0).toUpperCase() : "");
// return {
// _id: proj._id,
// projectName: proj.projectName,
// thumbnail: proj.thumbnail,
// createdBy: {
// _id: creator?._id,
// userName: creator?.userName,
// profilePicture: profile,
// // profile: profileData || ExistingUser.userName.charAt(0)
// },
// };
// });
// return { status: "Success", data: projectDatas };
// console.log('formattedProjects: ', formattedProjects);
return { status: "Success", data: projectDatas }; return { status: "Success", data: projectDatas };
} catch (error: unknown) { } catch (error: unknown) {
if (error instanceof Error) { if (error instanceof Error) {
@@ -360,6 +382,12 @@ export const ViewProjectService = async (
return { status: "Success", data: projectData || [] }; return { status: "Success", data: projectData || [] };
} catch (error: unknown) { } catch (error: unknown) {
if (error instanceof mongoose.Error.CastError) {
return {
status: "Invalid ID",
data: `Invalid value for ${error.path}: ${error.value}`,
};
}
if (error instanceof Error) { if (error instanceof Error) {
return { return {
status: error.message, status: error.message,
@@ -371,7 +399,7 @@ export const ViewProjectService = async (
} }
} }
}; };
// - working
export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => { export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => {
try { try {
const { projectId, organization, userId } = data; const { projectId, organization, userId } = data;
@@ -407,6 +435,12 @@ export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => {
if (!deleteProject) return { status: "Project Delete unsuccessfull" }; if (!deleteProject) return { status: "Project Delete unsuccessfull" };
return { status: "Success" ,data:deleteProject}; return { status: "Success" ,data:deleteProject};
} catch (error: unknown) { } catch (error: unknown) {
if (error instanceof mongoose.Error.CastError) {
return {
status: "Invalid ID",
data: `Invalid value for ${error.path}: ${error.value}`,
};
}
if (error instanceof Error) { if (error instanceof Error) {
return { return {
status: error.message, status: error.message,
@@ -418,7 +452,7 @@ export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => {
} }
} }
}; };
// - working
export const projectModification = async ( export const projectModification = async (
data: ProjectUpdate data: ProjectUpdate
): Promise<Iresponse> => { ): Promise<Iresponse> => {
@@ -468,6 +502,12 @@ export const projectModification = async (
if (!updateProject) return { status: "Project updated unsuccessfull" }; if (!updateProject) return { status: "Project updated unsuccessfull" };
return { status: "Success" ,data:updateProject}; return { status: "Success" ,data:updateProject};
} catch (error: unknown) { } catch (error: unknown) {
if (error instanceof mongoose.Error.CastError) {
return {
status: "Invalid ID",
data: `Invalid value for ${error.path}: ${error.value}`,
};
}
if (error instanceof Error) { if (error instanceof Error) {
return { return {
status: error.message, status: error.message,
@@ -479,7 +519,7 @@ export const projectModification = async (
} }
} }
}; };
// - working
export const projectClear = async (data: IProjectView): Promise<Iresponse> => { export const projectClear = async (data: IProjectView): Promise<Iresponse> => {
try { try {
const { projectId, organization, userId } = data; const { projectId, organization, userId } = data;
@@ -506,6 +546,12 @@ export const projectClear = async (data: IProjectView): Promise<Iresponse> => {
// } // }
return { status: "Success" }; return { status: "Success" };
} catch (error: unknown) { } catch (error: unknown) {
if (error instanceof mongoose.Error.CastError) {
return {
status: "Invalid ID",
data: `Invalid value for ${error.path}: ${error.value}`,
};
}
if (error instanceof Error) { if (error instanceof Error) {
return { return {
status: error.message, status: error.message,