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 + }} ); }