From 0bdb5013f7a19c1bc34c7f3c0702111833a0daf3 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Sat, 22 Nov 2025 01:10:37 -0600 Subject: [PATCH] veamo --- nuxt4/app/components/lotes/Trazabilidad.vue | 6 +- .../components/lotes/TrazabilidadGraph.vue | 233 ++++++++++++++++++ nuxt4/app/composables/useLotes.ts | 1 + .../server/api/lotes/[id]/trazabilidad.get.ts | 8 + nuxt4/server/database/01_schema.sql | 9 +- nuxt4/server/utils/queries.ts | 1 + 6 files changed, 254 insertions(+), 4 deletions(-) create mode 100644 nuxt4/app/components/lotes/TrazabilidadGraph.vue diff --git a/nuxt4/app/components/lotes/Trazabilidad.vue b/nuxt4/app/components/lotes/Trazabilidad.vue index 0f9bb06..2ea062f 100644 --- a/nuxt4/app/components/lotes/Trazabilidad.vue +++ b/nuxt4/app/components/lotes/Trazabilidad.vue @@ -38,7 +38,10 @@ - + + + +

Historial

@@ -107,6 +110,7 @@ diff --git a/nuxt4/app/composables/useLotes.ts b/nuxt4/app/composables/useLotes.ts index 65cc72d..014b714 100644 --- a/nuxt4/app/composables/useLotes.ts +++ b/nuxt4/app/composables/useLotes.ts @@ -28,6 +28,7 @@ export interface TrazabilidadRow { operacion_id: string | null operacion_tipo: string | null profundidad: number + parent_lote_id: string | null } export const useLotes = () => { diff --git a/nuxt4/server/api/lotes/[id]/trazabilidad.get.ts b/nuxt4/server/api/lotes/[id]/trazabilidad.get.ts index da354a1..677e7f8 100644 --- a/nuxt4/server/api/lotes/[id]/trazabilidad.get.ts +++ b/nuxt4/server/api/lotes/[id]/trazabilidad.get.ts @@ -18,6 +18,14 @@ export default defineEventHandler(async (event) => { }) } + const isUuid = /^[0-9a-fA-F-]{36}$/.test(id) + if (!isUuid) { + throw createError({ + statusCode: 400, + statusMessage: 'ID de lote inválido', + }) + } + // Obtener trazabilidad completa const trazabilidad = await getTrazabilidad(id) diff --git a/nuxt4/server/database/01_schema.sql b/nuxt4/server/database/01_schema.sql index 8af8c82..24bdfb7 100644 --- a/nuxt4/server/database/01_schema.sql +++ b/nuxt4/server/database/01_schema.sql @@ -134,7 +134,8 @@ RETURNS TABLE ( cantidad_kg NUMERIC, operacion_id UUID, operacion_tipo TEXT, - profundidad INTEGER + profundidad INTEGER, + parent_lote_id UUID ) AS $$ BEGIN RETURN QUERY @@ -147,7 +148,8 @@ BEGIN l.cantidad_kg, ol.operacion_id, o.tipo AS operacion_tipo, - 0 AS profundidad + 0 AS profundidad, + NULL::UUID AS parent_lote_id FROM lotes l LEFT JOIN operacion_lotes ol ON ol.lote_id = l.id AND ol.rol = 'output' LEFT JOIN operaciones o ON o.id = ol.operacion_id @@ -163,7 +165,8 @@ BEGIN l2.cantidad_kg, ol2.operacion_id, o2.tipo AS operacion_tipo, - t.profundidad + 1 + t.profundidad + 1, + t.lote_id AS parent_lote_id FROM trazabilidad t JOIN operacion_lotes ol_in ON ol_in.operacion_id = t.operacion_id diff --git a/nuxt4/server/utils/queries.ts b/nuxt4/server/utils/queries.ts index 32913ce..fc127b6 100644 --- a/nuxt4/server/utils/queries.ts +++ b/nuxt4/server/utils/queries.ts @@ -38,6 +38,7 @@ export interface TrazabilidadRow { operacion_id: string | null operacion_tipo: string | null profundidad: number + parent_lote_id: string | null } export interface LoteConOrigen extends Lote {