Skip to content

Commit

Permalink
Merge pull request #46 from BaseAdresseNationale/antoineludeau/fix-co…
Browse files Browse the repository at this point in the history
…mmon-toponyms-delete-order

Fix common toponyms delete order
  • Loading branch information
antoineludeau authored Sep 20, 2023
2 parents c84c178 + 65631e6 commit 6d362c5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/bal-converter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ export const sendBalToBan = async (bal: string) => {
const banAddressesIdsToDelete = addressIdsReport.idsToDelete;

// Order is important here. Need to handle common toponyms first, then adresses
const responseCommonToponyms = await Promise.all([
const responseCommonToponymsPromises = ([
banToponymsToAdd.length > 0 && createCommonToponyms(banToponymsToAdd),
banToponymsToUpdate.length > 0 && updateCommonToponyms(banToponymsToUpdate),
banToponymsIdsToDelete.length > 0 &&
deleteCommonToponyms(banToponymsIdsToDelete),
]);

const responseAddresses = await Promise.all([
Expand All @@ -65,6 +63,13 @@ export const sendBalToBan = async (bal: string) => {
deleteAddresses(banAddressesIdsToDelete),
]);

// To delete common toponyms, we need to wait for addresses to be deleted first
responseCommonToponymsPromises.push(banToponymsIdsToDelete.length > 0 &&
deleteCommonToponyms(banToponymsIdsToDelete),
)

const responseCommonToponyms = await Promise.all(responseCommonToponymsPromises);

const responses = [...responseAddresses, ...responseCommonToponyms];

return responses.reduce((acc, cur, i) => {
Expand Down

0 comments on commit 6d362c5

Please sign in to comment.