From a910ca9c857f6f81450a484e01367774ee99f0fd Mon Sep 17 00:00:00 2001 From: Jugurtha Bouhadoun Date: Fri, 7 Jun 2024 12:56:20 +0200 Subject: [PATCH] get the main commune --- lib/api-etablissements-public.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/api-etablissements-public.js b/lib/api-etablissements-public.js index f4888b1e2..79b1dff71 100644 --- a/lib/api-etablissements-public.js +++ b/lib/api-etablissements-public.js @@ -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 }