Skip to content

Commit

Permalink
Hot fix to handle undefined legacyCommonToponymId
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineludeau committed Sep 25, 2024
1 parent f705e7b commit 62de7b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/api/consumers/export-to-exploitation-db-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ export default async function exportToExploitationDB({data}) {

// Format the data and calculate the fantoir code, tiles and postal code
const pageDataWithExtraDataCalculation = pageData.map(address => calculateExtraDataForAddress(address, cog, commonToponymIDFantoirCodeMap))
const formatedPageDataForLegacy = pageDataWithExtraDataCalculation.map(address => formatAddressDataForLegacy(address, district, commonToponymLegacyIDCommonToponymIDMap, addressLegacyIDSet))
const formatedPageDataForLegacy = pageDataWithExtraDataCalculation
.map(address => formatAddressDataForLegacy(address, district, commonToponymLegacyIDCommonToponymIDMap, addressLegacyIDSet))
.filter(Boolean)

// Insert the data in the temp collection
tempAddressCollection.insertMany(formatedPageDataForLegacy, {ordered: false})
Expand Down
5 changes: 5 additions & 0 deletions lib/api/consumers/format-to-legacy-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ export const formatAddressDataForLegacy = (address, district, commonToponymLegac

// Ids
const legacyCommonToponymId = commonToponymLegacyIDCommonToponymIDMap.get(mainCommonToponymID)
// Temporary check : if the legacy common toponym id is not found, we don't create the address
if (!legacyCommonToponymId) {
return
}

const legacyInteropKey = `${legacyCommonToponymId}_${String(number).padStart(5, '0')}${suffix ? `_${suffix}` : ''}`.toLowerCase()
const legacyID = getAddressLegacyId(addressLegacyIDSet, legacyInteropKey)
addressLegacyIDSet.add(legacyID)
Expand Down

0 comments on commit 62de7b6

Please sign in to comment.