feat(aep): carte AEP — push Gitea 2026-04-28
This commit is contained in:
16
server/routes/api/avis.post.ts
Normal file
16
server/routes/api/avis.post.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const config = useRuntimeConfig()
|
||||
const body = await readBody(event)
|
||||
const url = `${config.nocodbUrl}/api/v2/tables/${config.avisTableId}/records`
|
||||
|
||||
const data = await $fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'xc-token': config.nocodbToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
|
||||
return data
|
||||
})
|
||||
13
server/routes/api/avis/[orgId].get.ts
Normal file
13
server/routes/api/avis/[orgId].get.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const config = useRuntimeConfig()
|
||||
const orgId = getRouterParam(event, 'orgId')
|
||||
const url = `${config.nocodbUrl}/api/v2/tables/${config.avisTableId}/records?where=(organisation_id,eq,${orgId})~and(status,eq,approved)`
|
||||
|
||||
const data = await $fetch(url, {
|
||||
headers: {
|
||||
'xc-token': config.nocodbToken,
|
||||
},
|
||||
})
|
||||
|
||||
return data
|
||||
})
|
||||
50
server/routes/api/organisations.get.ts
Normal file
50
server/routes/api/organisations.get.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { readFileSync } from 'fs'
|
||||
import { resolve } from 'path'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
// Paramètre optionnel ?format=map pour retourner uniquement les champs carte
|
||||
const query = getQuery(event)
|
||||
|
||||
try {
|
||||
// NocoDB V2 — table organisations, filtre approved + published
|
||||
const url = `${config.nocodbUrl}/api/v2/tables/${config.orgTableId}/records?where=(moderation_status,eq,approved)&limit=300&sort=-Id`
|
||||
|
||||
const data: any = await $fetch(url, {
|
||||
headers: { 'xc-token': config.nocodbToken },
|
||||
timeout: 8000,
|
||||
})
|
||||
|
||||
return { list: data?.list ?? [], source: 'nocodb' }
|
||||
} catch (err) {
|
||||
// Fallback seed JSON pour dev local si NocoDB inaccessible
|
||||
console.warn('[NAV API] NocoDB inaccessible, fallback seed JSON:', err)
|
||||
|
||||
try {
|
||||
const seedPath = resolve(process.cwd(), 'V2-cadrage/seed-94-fiches-v2.json')
|
||||
const raw = readFileSync(seedPath, 'utf-8')
|
||||
const seed: any[] = JSON.parse(raw)
|
||||
|
||||
// Normaliser le seed au format NocoDB (ajouter Id fictif)
|
||||
const list = seed.map((item: any, i: number) => ({
|
||||
Id: 1000 + i,
|
||||
nom: item.nom,
|
||||
url: item.url,
|
||||
description: item.description,
|
||||
echelle: item.echelle,
|
||||
tags_fonction: item.fonctions?.join(',') ?? '',
|
||||
territoire: item.territoire,
|
||||
localisation_ville: item.ville,
|
||||
latitude: item.lat,
|
||||
longitude: item.lon,
|
||||
moderation_status: 'approved',
|
||||
prioritaire: false,
|
||||
}))
|
||||
|
||||
return { list, source: 'seed' }
|
||||
} catch (seedErr) {
|
||||
throw createError({ statusCode: 503, message: 'Service indisponible — NocoDB et seed inaccessibles' })
|
||||
}
|
||||
}
|
||||
})
|
||||
16
server/routes/api/organisations.post.ts
Normal file
16
server/routes/api/organisations.post.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const config = useRuntimeConfig()
|
||||
const body = await readBody(event)
|
||||
const url = `${config.nocodbUrl}/api/v2/tables/${config.orgTableId}/records`
|
||||
|
||||
const data = await $fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'xc-token': config.nocodbToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
|
||||
return data
|
||||
})
|
||||
17
server/routes/api/organisations/[id].get.ts
Normal file
17
server/routes/api/organisations/[id].get.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const config = useRuntimeConfig()
|
||||
const id = getRouterParam(event, 'id')
|
||||
const url = `${config.nocodbUrl}/api/v2/tables/${config.orgTableId}/records?where=(Id,eq,${id})&limit=1`
|
||||
|
||||
const data: any = await $fetch(url, {
|
||||
headers: {
|
||||
'xc-token': config.nocodbToken,
|
||||
},
|
||||
})
|
||||
|
||||
const record = data?.list?.[0] ?? null
|
||||
if (!record) {
|
||||
throw createError({ statusCode: 404, message: 'Organisation non trouvée' })
|
||||
}
|
||||
return record
|
||||
})
|
||||
Reference in New Issue
Block a user