feat : ajout de l'api de l'état pour chercher les villes via le CP

This commit is contained in:
tristan
2026-03-18 15:06:21 +01:00
parent 92f54f600f
commit fbfc7acfe4
5 changed files with 83 additions and 76 deletions
+16
View File
@@ -0,0 +1,16 @@
export interface CommuneData {
nom: string
code: string
}
export async function getCommunesByPostalCode(postalCode: string): Promise<CommuneData[]> {
const config = useRuntimeConfig()
const base = config.public.geoApiBase
try {
return await $fetch<CommuneData[]>(`${base}/communes`, {
params: { codePostal: postalCode, fields: 'nom', format: 'json' }
})
} catch {
return []
}
}