From 0b9d6f801e4e2138485c53ea7265d4db8b3beb12 Mon Sep 17 00:00:00 2001 From: =bhagwanSingh Date: Fri, 21 Nov 2025 15:04:11 +0530 Subject: [PATCH] Bug fixed client & VA not updating on adding project with respected Ids --- src/helper/updateEntityRelationships.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/helper/updateEntityRelationships.js b/src/helper/updateEntityRelationships.js index 5a321f1..a689f87 100644 --- a/src/helper/updateEntityRelationships.js +++ b/src/helper/updateEntityRelationships.js @@ -23,7 +23,8 @@ async function updateEntityRelationships(data) { clientId, { $addToSet: { - projectIds: projectId + projectIds: projectId, + vaIds: vaId } }, { new: true } @@ -37,7 +38,8 @@ async function updateEntityRelationships(data) { { _id: { $in: vaId } }, { $addToSet: { - projectIds: projectId + projectIds: projectId, + clientIds: clientId } } ); @@ -49,6 +51,8 @@ async function updateEntityRelationships(data) { if (clientId) { projectUpdateData.clientId = clientId; } + + // 🐞🐞🐞 Here Duplicate Entry of Va is Created if SF pass same va multiple times in same req if (vaId && Array.isArray(vaId)) { projectUpdateData.vaAssigned = vaId; } @@ -202,7 +206,10 @@ async function removeEntityRelationships(data) { if (clientId) { await ClientModel.findByIdAndUpdate( clientId, - { $pull: { projectIds: projectId } } + {$pull: { + projectIds: projectId, + vaIds: vaId + }} ); } @@ -210,7 +217,11 @@ async function removeEntityRelationships(data) { if (vaId && Array.isArray(vaId)) { await VAModel.updateMany( { _id: { $in: vaId } }, - { $pull: { projectIds: projectId } } + { $pull: { + projectIds: projectId, + // 🐞🐞🐞 Here before removing we need to check if VA is still assigned to other projects of the same client + clientIds: clientId + }} ); }