From ce7bec7d4c2675233b2fc6821a4c36f3388b7ea8 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Wed, 29 Oct 2025 10:32:10 -0600 Subject: [PATCH] =?UTF-8?q?Fix:=20corregir=20tipos=20de=20par=C3=A1metros?= =?UTF-8?q?=20para=20queries=20nativas=20SQL=20de=20Metabase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cambios principales: - Cambiar tipo de parámetros de fecha de 'date/single' a 'text' - Cambiar tipo de parámetro booleano de 'category' a 'boolean' - Cambiar tipo de parámetros de categoría de 'category' a 'text' Las queries SQL nativas en Metabase usan template-tags con tipos específicos que deben coincidir exactamente con el tipo definido en el template-tag, no con los tipos de UI de Metabase. Archivos modificados: - server/api/metabase/panorama.post.ts - server/api/metabase/informe.post.ts Resuelve el problema donde todas las queries retornaban error 500 y respuestas vacías debido a tipos de parámetros incompatibles. --- nuxt4-app/server/api/metabase/informe.post.ts | 18 +++++++++--------- nuxt4-app/server/api/metabase/panorama.post.ts | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/nuxt4-app/server/api/metabase/informe.post.ts b/nuxt4-app/server/api/metabase/informe.post.ts index 598f386..199b625 100644 --- a/nuxt4-app/server/api/metabase/informe.post.ts +++ b/nuxt4-app/server/api/metabase/informe.post.ts @@ -38,21 +38,21 @@ export default defineEventHandler(async (event) => { } // Build parameters array for Metabase queries - // Convertir null a string vacío para que las queries usen NULLIF correctamente + // Las queries SQL nativas usan template-tags de tipo 'text' para fechas, no 'date/single' const buildParameters = (includeGranularidad: boolean = false) => { const params = [ { - type: 'date/single', + type: 'text', target: ['variable', ['template-tag', 'fecha_desde']], value: fecha_desde || '' }, { - type: 'date/single', + type: 'text', target: ['variable', ['template-tag', 'fecha_hasta']], value: fecha_hasta || '' }, { - type: 'category', + type: 'boolean', target: ['variable', ['template-tag', 'incluir_anulados']], value: incluir_anulados }, @@ -62,22 +62,22 @@ export default defineEventHandler(async (event) => { value: cliente_ids }, { - type: 'category', + type: 'text', target: ['variable', ['template-tag', 'tipos']], value: tipos }, { - type: 'category', + type: 'text', target: ['variable', ['template-tag', 'estados']], value: estados }, { - type: 'category', + type: 'text', target: ['variable', ['template-tag', 'ubicaciones']], value: ubicaciones }, { - type: 'category', + type: 'text', target: ['variable', ['template-tag', 'calidades']], value: calidades } @@ -85,7 +85,7 @@ export default defineEventHandler(async (event) => { if (includeGranularidad) { params.push({ - type: 'category', + type: 'text', target: ['variable', ['template-tag', 'granularidad']], value: granularidad }) diff --git a/nuxt4-app/server/api/metabase/panorama.post.ts b/nuxt4-app/server/api/metabase/panorama.post.ts index 0342bc9..14c4470 100644 --- a/nuxt4-app/server/api/metabase/panorama.post.ts +++ b/nuxt4-app/server/api/metabase/panorama.post.ts @@ -34,20 +34,20 @@ export default defineEventHandler(async (event) => { console.log('[Panorama] Cards to execute:', Object.keys(cards)) // Build parameters array for Metabase queries - // Convertir null a string vacío para que las queries usen NULLIF correctamente + // Las queries SQL nativas usan template-tags de tipo 'text' para fechas, no 'date/single' const parameters = [ { - type: 'date/single', + type: 'text', target: ['variable', ['template-tag', 'fecha_desde']], value: fecha_desde || '' }, { - type: 'date/single', + type: 'text', target: ['variable', ['template-tag', 'fecha_hasta']], value: fecha_hasta || '' }, { - type: 'category', + type: 'boolean', target: ['variable', ['template-tag', 'incluir_anulados']], value: incluir_anulados }