diff --git a/nuxt4-app/server/api/metabase/informe.post.ts b/nuxt4-app/server/api/metabase/informe.post.ts index 199b625..27a1de9 100644 --- a/nuxt4-app/server/api/metabase/informe.post.ts +++ b/nuxt4-app/server/api/metabase/informe.post.ts @@ -39,6 +39,7 @@ export default defineEventHandler(async (event) => { // Build parameters array for Metabase queries // Las queries SQL nativas usan template-tags de tipo 'text' para fechas, no 'date/single' + // IMPORTANTE: Solo incluir parámetros con valores para que Metabase no active filtros opcionales con arrays vacíos const buildParameters = (includeGranularidad: boolean = false) => { const params = [ { @@ -55,33 +56,49 @@ export default defineEventHandler(async (event) => { type: 'boolean', target: ['variable', ['template-tag', 'incluir_anulados']], value: incluir_anulados - }, - { + } + ] + + // Solo agregar filtros opcionales si tienen valores (no vacíos) + if (cliente_ids && Array.isArray(cliente_ids) && cliente_ids.length > 0) { + params.push({ type: 'number', target: ['variable', ['template-tag', 'cliente_ids']], value: cliente_ids - }, - { + }) + } + + if (tipos && Array.isArray(tipos) && tipos.length > 0) { + params.push({ type: 'text', target: ['variable', ['template-tag', 'tipos']], value: tipos - }, - { + }) + } + + if (estados && Array.isArray(estados) && estados.length > 0) { + params.push({ type: 'text', target: ['variable', ['template-tag', 'estados']], value: estados - }, - { + }) + } + + if (ubicaciones && Array.isArray(ubicaciones) && ubicaciones.length > 0) { + params.push({ type: 'text', target: ['variable', ['template-tag', 'ubicaciones']], value: ubicaciones - }, - { + }) + } + + if (calidades && Array.isArray(calidades) && calidades.length > 0) { + params.push({ type: 'text', target: ['variable', ['template-tag', 'calidades']], value: calidades - } - ] + }) + } if (includeGranularidad) { params.push({