Skip to content

Commit

Permalink
Merge pull request #181 from etalab/anciens-codes
Browse files Browse the repository at this point in the history
Update to support anciens INSEE codes
  • Loading branch information
ThomasG77 authored Nov 21, 2023
2 parents bdfef63 + 8db1acd commit 6d4a534
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions build/communes.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ async function buildCommunes() {
codeRegion: commune.region,
codesPostaux: [...(commune.codesPostaux || [])].sort(),
population: commune.population,
anciensCodes: commune.anciensCodes || [],
zone: commune.zone
}

Expand Down
10 changes: 10 additions & 0 deletions definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ parameters:
- codeRegion
- region
- population
- anciensCodes
- deleguees
- associees
- zone
Expand Down Expand Up @@ -254,6 +255,10 @@ paths:
in: query
description: Code de la commune si on a un arrondissement
type: string
- name: ancienCode
in: query
description: Code INSEE ancien de la commune
type: string
- $ref: '#/parameters/zoneParam'
- $ref: '#/parameters/typeCommune'
- $ref: '#/parameters/communeFieldsParam'
Expand Down Expand Up @@ -719,6 +724,11 @@ definitions:
population:
type: integer
description: Population municipale
anciensCodes:
type: array
description: Liste des anciens codes INSEE associés à la commune
items:
type: string
surface:
type: number
format: float
Expand Down
3 changes: 2 additions & 1 deletion lib/communes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const schema = {
codeDepartement: {type: 'token', queryWith: 'codeDepartement'},
codeRegion: {type: 'token', queryWith: 'codeRegion'},
zone: {type: 'token', queryWith: 'zone', multiple: 'OR'},
contour: {type: 'geo', queryWith: 'pointInContour'}
contour: {type: 'geo', queryWith: 'pointInContour'},
anciensCodes: {type: 'tokenList', queryWith: 'ancienCode'}
}

function getIndexedDb(options = {}) {
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ if (process.env.COMMUNES_ASSOCIEES_DELEGUEES) {

/* Communes */
app.get('/communes', initLimit(), initCommuneFields, initCommuneFormat, (req, res) => {
const query = pick(req.query, 'type', 'code', 'codePostal', 'nom', 'siren', 'deleguees', 'associees', 'codeEpci', 'codeDepartement', 'codeRegion', 'boost', 'zone', 'codeParent')
const query = pick(req.query, 'type', 'code', 'codePostal', 'nom', 'siren', 'deleguees', 'associees', 'codeEpci', 'codeDepartement', 'codeRegion', 'boost', 'zone', 'codeParent', 'ancienCode')
if (req.query.lat && req.query.lon) {
const lat = parseFloat(req.query.lat)
const lon = parseFloat(req.query.lon)
Expand Down

0 comments on commit 6d4a534

Please sign in to comment.