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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -13,7 +13,11 @@ interface IcollectionNode {
collectionName: string;
type: string;
organization: string;
position: [number];
position: {
x: number;
y: number;
zoom: number;
};
}
interface IAttribute {
key: string;
@@ -34,7 +38,11 @@ interface IcollectionNodeName {
lineType?: string;
borderThickness?: number;
cornerRadius?: number;
position?: [number];
position?: {
x: number;
y: number;
zoom: number;
};
}
interface IcollectionAttributes {
projectId: string;
@@ -92,15 +100,6 @@ interface IAttributesUpdate {
organization: string;
collectionNodeId: string;
attributes: IupdateChange[];
// fieldId: string;
// key?: string;
// type?: string;
// primary: boolean;
// required?: boolean;
// defaultValue?: any;
// unique?: boolean;
// index?: boolean;
// isIdentifier?: boolean;
}
interface IAttributesDel {
projectId: string;
@@ -121,7 +120,11 @@ interface IDuplicateCollectionNode {
collectionNodeId: string;
organization: string;
collectionName: string;
position: [number];
position: {
x: number;
y: number;
zoom: number;
};
attributes: [];
}
interface IDuplicateattributes {
@@ -131,6 +134,8 @@ interface IDuplicateattributes {
organization: string;
attrKey: string;
}
// - working
export const Nodecreation = async (
data: IcollectionNode
): Promise<Iresponse> => {
@@ -161,10 +166,6 @@ export const Nodecreation = async (
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);
@@ -201,7 +202,7 @@ export const Nodecreation = async (
}
}
};
// - working
export const updatecollection = async (
data: IcollectionNodeName
): 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 (
data: IcollectionNodes
): Promise<Iresponse> => {
@@ -462,16 +340,19 @@ export const GetNodesInProject = async (
);
if (refAttribute) {
// targetFieldKey = refAttribute.key;
targetFieldKey = refAttribute.key;
}
}
return {
edgeId: e._id,
id: `e_source-${e.from.collection_id}-${e.from.collection_id}_${targetFieldKey}`,
source: e.from.collection_id,
sourceHandle: e.from.field,
sourceHandle: `source-${e.from.collection_id}-${e.from.field}`,
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;
});
console.log("filteredEdges: ", filteredEdges);
const finalResult = {
nodes: formattedCollections,
edges: filteredEdges,
@@ -536,7 +418,7 @@ export const GetNodesInProject = async (
}
}
};
// - working
export const UpdateAttributes = async (
// data: IAttributesEdit
data: IAttributesUpdate
@@ -597,7 +479,7 @@ export const UpdateAttributes = async (
parentCollectionNodeId: collectionNodeId,
attributeparentId: fieldId,
attributes: [],
// position: [0, 0, 0],
position: { x: 0, y: 0, zoom: 2 },
});
existingCollection.isSubCollection = true;
await existingCollection.save();
@@ -631,6 +513,28 @@ export const UpdateAttributes = async (
},
{ 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" };
}
@@ -647,267 +551,7 @@ export const UpdateAttributes = async (
}
};
// export const DelAttributes = async (
// 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",
// };
// }
// }
// };
// - working
export const delCollection = async (
data: ICollectionDelete
): Promise<Iresponse> => {
@@ -1284,124 +928,12 @@ export const GetcollectionLists = async (
}
};
// export const addAttributes = async (
// 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" };
// }
// };
// - working
export const DelAttributes = async (
data: IAttributesDel
): Promise<Iresponse> => {
const { organization, userId, projectId, collectionNodeId, fieldId } = data;
console.log('data: ', data);
console.log("data: ", data);
try {
const existingUser = await userModel(organization).findOne({
@@ -1422,7 +954,7 @@ export const DelAttributes = async (
isArchive: false,
"attributes._id": new mongoose.Types.ObjectId(fieldId),
});
console.log('existingCollection: ', existingCollection);
console.log("existingCollection: ", existingCollection);
if (!existingCollection) return { status: "Collection not found" };
const attribute = existingCollection.attributes.find(
@@ -1480,7 +1012,7 @@ export const DelAttributes = async (
return { status: "An unexpected error occurred" };
}
};
// - working
export const addAttributes = async (
data: IcollectionAttributes
): Promise<Iresponse> => {

View File

@@ -8,6 +8,7 @@ import userDataModel from "../model/userDataModel";
import userModel from "../model/userModel";
import versionModel from "../model/versionModel";
import groupModel from "../model/groupModel";
import mongoose from "mongoose";
interface Iresponse {
status: string;
data?: any;
@@ -62,7 +63,7 @@ export const previousVersion = async (
return result;
};
// - working
export const projectCreationService = async (
data: IProject
): Promise<Iresponse> => {
@@ -219,16 +220,37 @@ export const projectDatas = async (data: IgetProject): Promise<Iresponse> => {
query;
}
const projectDatas = await ProjectType(organization)
.find(query)
.select("projectName createdBy thumbnail")
.populate({
path: "createdBy",
model: userModel(organization),
select: "userName",
})
.skip(skipdata)
.limit(limitdata);
.find(query)
.select("projectName createdBy thumbnail")
.populate({
path: "createdBy",
model: userModel(organization),
select: "userName profilePicture",
})
.skip(skipdata)
.limit(limitdata);
console.log('projectDatas: ', projectDatas);
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 };
} catch (error: unknown) {
if (error instanceof Error) {
@@ -360,6 +382,12 @@ export const ViewProjectService = async (
return { status: "Success", data: projectData || [] };
} 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) {
return {
status: error.message,
@@ -371,7 +399,7 @@ export const ViewProjectService = async (
}
}
};
// - working
export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => {
try {
const { projectId, organization, userId } = data;
@@ -407,6 +435,12 @@ export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => {
if (!deleteProject) return { status: "Project Delete unsuccessfull" };
return { status: "Success" ,data:deleteProject};
} 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) {
return {
status: error.message,
@@ -418,7 +452,7 @@ export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => {
}
}
};
// - working
export const projectModification = async (
data: ProjectUpdate
): Promise<Iresponse> => {
@@ -468,6 +502,12 @@ export const projectModification = async (
if (!updateProject) return { status: "Project updated unsuccessfull" };
return { status: "Success" ,data:updateProject};
} 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) {
return {
status: error.message,
@@ -479,7 +519,7 @@ export const projectModification = async (
}
}
};
// - working
export const projectClear = async (data: IProjectView): Promise<Iresponse> => {
try {
const { projectId, organization, userId } = data;
@@ -506,6 +546,12 @@ export const projectClear = async (data: IProjectView): Promise<Iresponse> => {
// }
return { status: "Success" };
} 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) {
return {
status: error.message,