feat : ajout de l'api de l'état pour chercher les villes via le CP
This commit is contained in:
@@ -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 []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user