Skip to content

Commit

Permalink
Fixed digest bal ids when no data
Browse files Browse the repository at this point in the history
antoineludeau committed May 22, 2024
1 parent e99cd4d commit 35b58d6
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 17 additions & 2 deletions lib/util/digest-ids-from-bal-address.cjs
Original file line number Diff line number Diff line change
@@ -4,18 +4,33 @@ const digestIDsFromBalAddress = (
balAddress,
version,
) => {
const defaultIDs = {
addressID: undefined,
mainTopoID: undefined,
secondaryTopoIDs: undefined,
districtID: undefined,
}

switch (version) {
case '1.4':
return {
...defaultIDs,
addressID: balAddress?.idBanAdresse,
mainTopoID: balAddress?.idBanToponyme,
secondaryTopoIDs: undefined,
districtID: balAddress?.idBanCommune,
}

default: {
case '1.3': {
const {uidAdresse: ids} = balAddress
return digestIDsFromBalUIDs(ids)
return {
...defaultIDs,
...digestIDsFromBalUIDs(ids)
}
}

default:
return defaultIDs
}
}

4 changes: 3 additions & 1 deletion lib/util/get-bal-address-version.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const getBalAddressVersion = balAddress => {
const getBalAddressVersion = (balAddress = {}) => {
const {idBanCommune: districtID, uidAdresse: ids} = balAddress

if (districtID) {
@@ -8,6 +8,8 @@ const getBalAddressVersion = balAddress => {
if (ids) {
return '1.3'
}

return '1.x'
}

module.exports = {getBalAddressVersion}

0 comments on commit 35b58d6

Please sign in to comment.