Files
Ferme/frontend/services/geo.ts
tristan fbfc7acfe4
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
feat : ajout de l'api de l'état pour chercher les villes via le CP
2026-03-18 15:06:21 +01:00

17 lines
411 B
TypeScript

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 []
}
}