Showing
6 changed files
with
21 additions
and
49 deletions
| ... | @@ -2,26 +2,14 @@ export const ssr = false; | ... | @@ -2,26 +2,14 @@ export const ssr = false; |
| 2 | 2 | ||
| 3 | import { error } from '@sveltejs/kit'; | 3 | import { error } from '@sveltejs/kit'; |
| 4 | 4 | ||
| 5 | -import { API_HOST } from '$lib/api.js'; | ||
| 6 | -const API_BASE = API_HOST + '/api/acteco'; | ||
| 7 | - | ||
| 8 | -// Jerarquía acteco: códigos con punto "1" → "1.1" → "1.1.1" | ||
| 9 | -// Todos tienen nivel "actividad" en la API, derivamos la profundidad del código | ||
| 10 | - | ||
| 11 | function getDepth(codigo) { | 5 | function getDepth(codigo) { |
| 12 | return String(codigo).split('.').length; | 6 | return String(codigo).split('.').length; |
| 13 | } | 7 | } |
| 14 | 8 | ||
| 15 | -function getParentCode(codigo) { | 9 | +export async function load({ params, fetch }) { |
| 16 | - const parts = String(codigo).split('.'); | ||
| 17 | - if (parts.length <= 1) return null; | ||
| 18 | - return parts.slice(0, -1).join('.'); | ||
| 19 | -} | ||
| 20 | - | ||
| 21 | -export async function load({ params }) { | ||
| 22 | const { codigo } = params; | 10 | const { codigo } = params; |
| 23 | 11 | ||
| 24 | - const res = await fetch(`${API_BASE}/${codigo}`); | 12 | + const res = await fetch(`/api/acteco-data?codigo=${codigo}&tipo=clasificador`); |
| 25 | if (!res.ok) throw error(404, 'Sector económico no encontrado'); | 13 | if (!res.ok) throw error(404, 'Sector económico no encontrado'); |
| 26 | const acteco = await res.json(); | 14 | const acteco = await res.json(); |
| 27 | 15 | ||
| ... | @@ -29,7 +17,7 @@ export async function load({ params }) { | ... | @@ -29,7 +17,7 @@ export async function load({ params }) { |
| 29 | let hijos = []; | 17 | let hijos = []; |
| 30 | 18 | ||
| 31 | try { | 19 | try { |
| 32 | - const clasRes = await fetch(`${API_BASE}/clasificador`); | 20 | + const clasRes = await fetch('/api/acteco-clasificador'); |
| 33 | if (clasRes.ok) { | 21 | if (clasRes.ok) { |
| 34 | const clasificador = await clasRes.json(); | 22 | const clasificador = await clasRes.json(); |
| 35 | const depth = getDepth(codigo); | 23 | const depth = getDepth(codigo); | ... | ... |
| 1 | +export const ssr = false; | ||
| 2 | + | ||
| 1 | import { error } from '@sveltejs/kit'; | 3 | import { error } from '@sveltejs/kit'; |
| 2 | 4 | ||
| 3 | -import { API_HOST } from '$lib/api.js'; | 5 | + |
| 4 | -const API_BASE = API_HOST + '/api/finfun'; | 6 | + |
| 5 | 7 | ||
| 6 | // Jerarquía finfun: Finalidad → Grupo Función → Función | 8 | // Jerarquía finfun: Finalidad → Grupo Función → Función |
| 7 | // Códigos con punto: "1" (finalidad), "1.1" (grpfuncion), "1.1.1" (función) | 9 | // Códigos con punto: "1" (finalidad), "1.1" (grpfuncion), "1.1.1" (función) |
| ... | @@ -26,7 +28,7 @@ export async function load({ params }) { | ... | @@ -26,7 +28,7 @@ export async function load({ params }) { |
| 26 | const { codigo } = params; | 28 | const { codigo } = params; |
| 27 | 29 | ||
| 28 | // Cargar datos del finfun desde la API | 30 | // Cargar datos del finfun desde la API |
| 29 | - const res = await fetch(`${API_BASE}/${codigo}`); | 31 | + const res = await fetch(`/api/finfun-data?codigo=${codigo}&tipo=clasificador`); |
| 30 | if (!res.ok) throw error(404, 'Finalidad/Función no encontrada'); | 32 | if (!res.ok) throw error(404, 'Finalidad/Función no encontrada'); |
| 31 | const finfun = await res.json(); | 33 | const finfun = await res.json(); |
| 32 | 34 | ||
| ... | @@ -37,7 +39,7 @@ export async function load({ params }) { | ... | @@ -37,7 +39,7 @@ export async function load({ params }) { |
| 37 | let hijos = []; | 39 | let hijos = []; |
| 38 | 40 | ||
| 39 | try { | 41 | try { |
| 40 | - const clasRes = await fetch(`${API_BASE}/clasificador`); | 42 | + const clasRes = await fetch(`/api/finfun-clasificador`); |
| 41 | if (clasRes.ok) { | 43 | if (clasRes.ok) { |
| 42 | const clasificador = await clasRes.json(); | 44 | const clasificador = await clasRes.json(); |
| 43 | 45 | ... | ... |
| ... | @@ -2,18 +2,13 @@ export const ssr = false; | ... | @@ -2,18 +2,13 @@ export const ssr = false; |
| 2 | 2 | ||
| 3 | import { error } from '@sveltejs/kit'; | 3 | import { error } from '@sveltejs/kit'; |
| 4 | 4 | ||
| 5 | -import { API_HOST } from '$lib/api.js'; | 5 | +export async function load({ params, fetch }) { |
| 6 | -const API_BASE = API_HOST + '/api/objeto'; | ||
| 7 | - | ||
| 8 | -export async function load({ params }) { | ||
| 9 | const { codigo } = params; | 6 | const { codigo } = params; |
| 10 | 7 | ||
| 11 | - // Cargar clasificador desde la API | 8 | + const res = await fetch(`/api/objeto-data?codigo=${codigo}&tipo=clasificador`); |
| 12 | - const res = await fetch(`${API_BASE}/${codigo}`); | ||
| 13 | if (!res.ok) throw error(404, 'Objeto no encontrado'); | 9 | if (!res.ok) throw error(404, 'Objeto no encontrado'); |
| 14 | const objeto = await res.json(); | 10 | const objeto = await res.json(); |
| 15 | 11 | ||
| 16 | - // Derivar padres e hijos del código | ||
| 17 | const nivel = objeto.nivel; | 12 | const nivel = objeto.nivel; |
| 18 | let padresCodes = []; | 13 | let padresCodes = []; |
| 19 | 14 | ||
| ... | @@ -32,19 +27,17 @@ export async function load({ params }) { | ... | @@ -32,19 +27,17 @@ export async function load({ params }) { |
| 32 | padresCodes = [codigo.charAt(0) + '0000']; | 27 | padresCodes = [codigo.charAt(0) + '0000']; |
| 33 | } | 28 | } |
| 34 | 29 | ||
| 35 | - // Cargar padres e hijos en paralelo desde la API | ||
| 36 | const [padresResults, hijosResult] = await Promise.all([ | 30 | const [padresResults, hijosResult] = await Promise.all([ |
| 37 | Promise.all(padresCodes.map(async (c) => { | 31 | Promise.all(padresCodes.map(async (c) => { |
| 38 | try { | 32 | try { |
| 39 | - const r = await fetch(`${API_BASE}/${c}`); | 33 | + const r = await fetch(`/api/objeto-data?codigo=${c}&tipo=clasificador`); |
| 40 | if (r.ok) return await r.json(); | 34 | if (r.ok) return await r.json(); |
| 41 | } catch {} | 35 | } catch {} |
| 42 | return null; | 36 | return null; |
| 43 | })), | 37 | })), |
| 44 | (async () => { | 38 | (async () => { |
| 45 | - // Hijos: buscar en el clasificador | ||
| 46 | try { | 39 | try { |
| 47 | - const r = await fetch(`${API_BASE}/clasificador`); | 40 | + const r = await fetch('/api/objeto-clasificador'); |
| 48 | if (!r.ok) return []; | 41 | if (!r.ok) return []; |
| 49 | const all = await r.json(); | 42 | const all = await r.json(); |
| 50 | 43 | ||
| ... | @@ -63,10 +56,5 @@ export async function load({ params }) { | ... | @@ -63,10 +56,5 @@ export async function load({ params }) { |
| 63 | const padres = padresResults.filter(Boolean).sort((a, b) => a.objeto.localeCompare(b.objeto)); | 56 | const padres = padresResults.filter(Boolean).sort((a, b) => a.objeto.localeCompare(b.objeto)); |
| 64 | const hijos = hijosResult.sort((a, b) => a.objeto.localeCompare(b.objeto)); | 57 | const hijos = hijosResult.sort((a, b) => a.objeto.localeCompare(b.objeto)); |
| 65 | 58 | ||
| 66 | - return { | 59 | + return { objeto, padres, hijos, nEntidades: 0 }; |
| 67 | - objeto, | ||
| 68 | - padres, | ||
| 69 | - hijos, | ||
| 70 | - nEntidades: 0 | ||
| 71 | - }; | ||
| 72 | } | 60 | } | ... | ... |
| ... | @@ -2,13 +2,10 @@ export const ssr = false; | ... | @@ -2,13 +2,10 @@ export const ssr = false; |
| 2 | 2 | ||
| 3 | import { error } from '@sveltejs/kit'; | 3 | import { error } from '@sveltejs/kit'; |
| 4 | 4 | ||
| 5 | -import { API_HOST } from '$lib/api.js'; | 5 | +export async function load({ params, fetch }) { |
| 6 | -const API_BASE = API_HOST + '/api/organismo'; | ||
| 7 | - | ||
| 8 | -export async function load({ params }) { | ||
| 9 | const { codigo } = params; | 6 | const { codigo } = params; |
| 10 | 7 | ||
| 11 | - const res = await fetch(`${API_BASE}/${codigo}`); | 8 | + const res = await fetch(`/api/organismo-data?codigo=${codigo}&tipo=clasificador`); |
| 12 | if (!res.ok) throw error(404, 'Organismo no encontrado'); | 9 | if (!res.ok) throw error(404, 'Organismo no encontrado'); |
| 13 | const organismo = await res.json(); | 10 | const organismo = await res.json(); |
| 14 | 11 | ||
| ... | @@ -16,7 +13,7 @@ export async function load({ params }) { | ... | @@ -16,7 +13,7 @@ export async function load({ params }) { |
| 16 | let hijos = []; | 13 | let hijos = []; |
| 17 | 14 | ||
| 18 | try { | 15 | try { |
| 19 | - const clasRes = await fetch(`${API_BASE}/clasificador`); | 16 | + const clasRes = await fetch('/api/organismo-clasificador'); |
| 20 | if (clasRes.ok) { | 17 | if (clasRes.ok) { |
| 21 | const clasificador = await clasRes.json(); | 18 | const clasificador = await clasRes.json(); |
| 22 | const current = clasificador.find(c => String(c.organismo) === codigo); | 19 | const current = clasificador.find(c => String(c.organismo) === codigo); | ... | ... |
| ... | @@ -2,13 +2,10 @@ export const ssr = false; | ... | @@ -2,13 +2,10 @@ export const ssr = false; |
| 2 | 2 | ||
| 3 | import { error } from '@sveltejs/kit'; | 3 | import { error } from '@sveltejs/kit'; |
| 4 | 4 | ||
| 5 | -import { API_HOST } from '$lib/api.js'; | 5 | +export async function load({ params, fetch }) { |
| 6 | -const API_BASE = API_HOST + '/api/rubro'; | ||
| 7 | - | ||
| 8 | -export async function load({ params }) { | ||
| 9 | const { codigo } = params; | 6 | const { codigo } = params; |
| 10 | 7 | ||
| 11 | - const res = await fetch(`${API_BASE}/${codigo}`); | 8 | + const res = await fetch(`/api/rubro-data?codigo=${codigo}&tipo=clasificador`); |
| 12 | if (!res.ok) throw error(404, 'Rubro no encontrado'); | 9 | if (!res.ok) throw error(404, 'Rubro no encontrado'); |
| 13 | const rubro = await res.json(); | 10 | const rubro = await res.json(); |
| 14 | 11 | ||
| ... | @@ -17,7 +14,7 @@ export async function load({ params }) { | ... | @@ -17,7 +14,7 @@ export async function load({ params }) { |
| 17 | let hijos = []; | 14 | let hijos = []; |
| 18 | 15 | ||
| 19 | try { | 16 | try { |
| 20 | - const clasRes = await fetch(`${API_BASE}/clasificador`); | 17 | + const clasRes = await fetch('/api/rubro-clasificador'); |
| 21 | if (clasRes.ok) { | 18 | if (clasRes.ok) { |
| 22 | const clasificador = await clasRes.json(); | 19 | const clasificador = await clasRes.json(); |
| 23 | const s = String(codigo).padStart(5, '0'); | 20 | const s = String(codigo).padStart(5, '0'); | ... | ... |
| ... | @@ -102,7 +102,7 @@ | ... | @@ -102,7 +102,7 @@ |
| 102 | // Resetear al cambiar de ubicación | 102 | // Resetear al cambiar de ubicación |
| 103 | let prevCodigo = codigoSeleccionado; | 103 | let prevCodigo = codigoSeleccionado; |
| 104 | $effect(() => { | 104 | $effect(() => { |
| 105 | - if (data.gestionInicial !== gestionSeleccionada || codigoSeleccionado !== prevCodigo) { | 105 | + if (codigoSeleccionado !== prevCodigo) { |
| 106 | prevCodigo = codigoSeleccionado; | 106 | prevCodigo = codigoSeleccionado; |
| 107 | gestionSeleccionada = data.gestionInicial; | 107 | gestionSeleccionada = data.gestionInicial; |
| 108 | distribucionesData = data.distribucionesData; | 108 | distribucionesData = data.distribucionesData; | ... | ... |
-
Please register or login to post a comment