Skip to content

Commit

Permalink
Merge pull request #47 from BaseAdresseNationale/antoineludeau/add-li…
Browse files Browse the repository at this point in the history
…eudit-complement-nom

Added labels from bal lieudit_complement_nom on address schema
  • Loading branch information
antoineludeau authored Sep 27, 2023
2 parents d8e90c0 + a218d19 commit 54b07df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
16 changes: 15 additions & 1 deletion src/bal-converter/helpers/bal-addr-to-ban-addr.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { BalAdresse } from "../../types/bal-types.js";
import type { LangISO639v3 } from "../../types/ban-generic-types.js";
import type { BalAdresse, LieuditComplementNomIsoCodeKey } from "../../types/bal-types.js";
import type { BanAddress } from "../../types/ban-types.js";

import { numberForTopo as IS_TOPO_NB } from "../bal-converter.config.js";
import { convertBalPositionTypeToBanPositionType } from "./bal-position-type-to-ban-position-type.js";
import digestIDsFromBalAddr from "./digest-ids-from-bal-addr.js";

const DEFAULT_BAN_ADDR_POSITION = "other";
const DEFAULT_ISO_LANG = "fra";

const balAddrToBanAddr = (
balAdresse: BalAdresse,
Expand All @@ -15,6 +17,17 @@ const balAddrToBanAddr = (
const addrNumber = balAdresse.numero || oldBanAddress?.number;
const positionType = convertBalPositionTypeToBanPositionType(balAdresse.position);
const suffix = balAdresse.suffixe
const isoCodeFromBalLieuDitComplementNom = (key: LangISO639v3) => key.trim().split("_")[3];
const labels = balAdresse.lieudit_complement_nom ? {
[DEFAULT_ISO_LANG]: balAdresse.lieudit_complement_nom,
...Object.fromEntries(
(
Object.keys(balAdresse).filter((key) =>
key.startsWith("lieudit_complement_nom_")
) as LieuditComplementNomIsoCodeKey[]
).map((key) => [isoCodeFromBalLieuDitComplementNom(key), balAdresse[key]])
),
} : undefined;
const meta = balAdresse.cad_parcelles && balAdresse.cad_parcelles.length > 0
? { cadastre: { ids: balAdresse.cad_parcelles } }
: undefined;
Expand All @@ -39,6 +52,7 @@ const balAddrToBanAddr = (
],
certified: balAdresse.certification_commune,
updateDate: balAdresse.date_der_maj,
...(labels ? {labels : Object.entries(labels).map(([isoCode, value]) => ({isoCode, value}))} : {}),
...(suffix ? {suffix} : {}),
...(meta ? {meta} : {}),
}
Expand Down
1 change: 1 addition & 0 deletions src/types/bal-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type CommuneNomIsoCodeKey = `commune_nom_${LangISO639v3}`;
export type CommuneDelegueeNomIsoCodeKey =
`commune_deleguee_nom_${LangISO639v3}`;
export type VoieNomIsoCodeKey = `voie_nom_${LangISO639v3}`;
export type LieuditComplementNomIsoCodeKey = `lieudit_complement_nom_${LangISO639v3}`;
export type LieuditComplementNomIsoCodeKey =
`lieudit_complement_nom_${LangISO639v3}`;

Expand Down
11 changes: 7 additions & 4 deletions src/types/ban-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export type Position = {
geometry: Geometry
};

export type Label = {
isoCode: LangISO639v3; // code ISO de la langue
value: string; // nom de la voie
}

export type BanDistrict = {
districtID: DistrictInseeID; // code INSEE de la commune
labels: {
Expand All @@ -33,10 +38,7 @@ export type BanDistricts = BanDistrict[];
export type BanCommonToponym = {
id?: BanCommonTopoID; // identifiant unique de la voie
districtID: DistrictInseeID; // code INSEE de la commune
labels: {
isoCode: LangISO639v3; // code ISO de la langue
value: string; // nom de la voie
}[];
labels: Label[];
geometry?: Geometry
updateDate: DateISO8601; // date de mise à jour de la voie
meta?: Meta
Expand All @@ -51,6 +53,7 @@ export type BanAddress = {
secondaryCommonToponymIDs?: BanCommonTopoID[]; // identifiant unique des toponymes secondaires
number: number; // numéro de l'adresse
suffix?: string;
labels?: Label[];
positions: Position[]; // positions géographiques de l'adresse
certified?: boolean;
updateDate: DateISO8601; // date de mise à jour de l'adresse
Expand Down

0 comments on commit 54b07df

Please sign in to comment.