Bug fixed client & VA not updating on adding project with respected Ids

This commit is contained in:
=bhagwanSingh 2025-11-21 15:04:11 +05:30
parent db51e213f1
commit 0b9d6f801e
1 changed files with 15 additions and 4 deletions

View File

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