Skip to content

Commit

Permalink
get the main commune
Browse files Browse the repository at this point in the history
  • Loading branch information
Jugurtha Bouhadoun committed Jun 7, 2024
1 parent 0b54553 commit a910ca9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/api-etablissements-public.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ export async function getMairie(codeCommune) {
const url = `${API_ETABLISSEMENTS_PUBLIC}/${route}?${query}`

const response = await _fetch(url)
const rawMairie = response?.results?.[0]
if (!rawMairie) {
if (!response?.results) {
return null
}

let rawMairie = response.results.find(result => !result.nom.toLowerCase().includes('mairie déléguée'))

if (!rawMairie) {
rawMairie = response.results[0]
}

const mairie = formatMairie(rawMairie)
return mairie
}

0 comments on commit a910ca9

Please sign in to comment.