+server.js
809 Bytes
import { API_HOST } from '$lib/api.js';
const API_BASE = API_HOST + '/api/entidad/clasificador';
export async function GET() {
try {
const res = await fetch(API_BASE);
if (!res.ok) throw new Error();
const data = await res.json();
// Mapear al formato que espera el treemap
const mapped = data
.filter(d => d.entidad !== 0)
.map(d => ({
entidad: d.entidad,
desc_entidad: d.desc_entidad,
sigla_entidad: d.sigla_entidad || '',
gestiones: d.gestiones || ''
}));
return new Response(JSON.stringify(mapped), {
headers: { 'Content-Type': 'application/json' }
});
} catch {
return new Response(JSON.stringify({ error: 'Failed to fetch' }), {
status: 500, headers: { 'Content-Type': 'application/json' }
});
}
}