Fix: Solo enviar par\u00e1metros con valores a Metabase para evitar filtros vac\u00edos
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 48s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 48s
Problema: Las queries de Metabase en el endpoint /api/metabase/informe retornaban 0 filas porque se enviaban par\u00e1metros con arrays vac\u00edos, lo cual activaba filtros condicionales sin valores. Soluci\u00f3n: Modificar buildParameters() para solo incluir par\u00e1metros opcionales (cliente_ids, tipos, estados, ubicaciones, calidades) cuando tengan valores (arrays no vac\u00edos). Los filtros condicionales [[...]] de Metabase ahora se omiten correctamente cuando no hay valores.
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user