Skip to content

Commit

Permalink
Merge pull request #471 from BaseAdresseNationale/antoineludeau/hot-f…
Browse files Browse the repository at this point in the history
…ix-undefined-cle-interop

Hot fix to handle undefined legacyCommonToponymId
  • Loading branch information
antoineludeau authored Sep 25, 2024
2 parents f705e7b + cdba1fb commit ca4db4d
Show file tree
Hide file tree
Showing 2 changed files with 9 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
6 changes: 6 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,12 @@ 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) {
console.log(`Address ${id} not created because its common toponym (id : ${mainCommonToponymID}) does not exist on this district (id : ${districtID} - cog: ${cog})`)
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 ca4db4d

Please sign in to comment.