Skip to content

Commit

Permalink
feat: Handled unique value edge case with deleted records (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik authored Jul 5, 2024
2 parents d490171 + ba3af87 commit dc67058
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ export class DoReReview extends BaseReview {
uniqueItems[field].add(item.record[field]);
});
});
const bulkOperations = [];
for (const key of Object.keys(uniqueItems)) {
const itemsArray = Array.from(uniqueItems[key]);
// Iterate over each value in unique field
for (const item of itemsArray) {
// update first occurance of data
bulkOperations.push({
updateOne: {
filter: { [`record.${key}`]: item },
update: { $set: { [`updated.${key}`]: true } },
},
});
// update second occurance of data for validity
bulkOperations.push({
updateOne: {
filter: { [`record.${key}`]: item, [`updated.${key}`]: false },
update: { $set: { [`updated.${key}`]: true } },
},
});
}
uniqueItems[key].clear();
}
await this._modal.bulkWrite(bulkOperations);

let result: ISaveResults = {
uploadId: _uploadId,
Expand Down

0 comments on commit dc67058

Please sign in to comment.