Skip to content

Commit

Permalink
SonarQube - Fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
kennsippell committed Nov 23, 2024
1 parent 17c4c04 commit 7af035c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/lib/hierarchy-operations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,27 @@ const HierarchyOperations = (db, options) => {
}

function replaceLineageInContacts(descendantsAndSelf, replacementLineage, destinationId) {
function replaceForSingleContact(doc) {
const docIsDestination = doc._id === destinationId;
const startingFromIdInLineage = options.merge || !docIsDestination ? destinationId : undefined;
const parentWasUpdated = lineageManipulation.replaceLineage(doc, 'parent', replacementLineage, startingFromIdInLineage, options);
const contactWasUpdated = lineageManipulation.replaceLineage(doc, 'contact', replacementLineage, destinationId, options);
const isUpdated = parentWasUpdated || contactWasUpdated;
if (isUpdated) {
result.push(doc);
}
}

const result = [];
for (const doc of descendantsAndSelf) {
const docIsDestination = doc._id === destinationId;
const startingFromIdInLineage = options.merge || !docIsDestination ? destinationId : undefined;

// skip top-level because it will be deleted
if (options.merge && docIsDestination) {
continue;
}

const parentWasUpdated = lineageManipulation.replaceLineage(doc, 'parent', replacementLineage, startingFromIdInLineage, options);
const contactWasUpdated = lineageManipulation.replaceLineage(doc, 'contact', replacementLineage, destinationId, options);
const isUpdated = parentWasUpdated || contactWasUpdated;
if (isUpdated) {
result.push(doc);
}
replaceForSingleContact(doc);
}

return result;
Expand Down

0 comments on commit 7af035c

Please sign in to comment.