Fix: corregir parsing de opciones-filtros (soportar strings y arrays)
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 46s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 46s
This commit is contained in:
@@ -55,12 +55,22 @@ export default defineEventHandler(async () => {
|
||||
data[col.name] = row[index]
|
||||
})
|
||||
|
||||
// Parse JSON arrays
|
||||
console.log('[API] Transformed data object:', data)
|
||||
console.log('[API] Column names:', cols.map((c: any) => c.name))
|
||||
|
||||
// Parse arrays - some come as JSON strings, others as arrays
|
||||
const parseIfString = (value: any) => {
|
||||
if (typeof value === 'string') {
|
||||
return JSON.parse(value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
return {
|
||||
ubicaciones: data.ubicaciones ? JSON.parse(data.ubicaciones) : [],
|
||||
calidades: data.calidades ? JSON.parse(data.calidades) : [],
|
||||
tipos: data.tipos ? JSON.parse(data.tipos) : [],
|
||||
estados: data.estados ? JSON.parse(data.estados) : []
|
||||
ubicaciones: data.ubicaciones ? parseIfString(data.ubicaciones) : [],
|
||||
calidades: data.calidades ? parseIfString(data.calidades) : [],
|
||||
tipos: data.tipos ? parseIfString(data.tipos) : [],
|
||||
estados: data.estados ? parseIfString(data.estados) : []
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('[API] Failed to fetch opciones de filtros from Metabase:', error)
|
||||
|
||||
Reference in New Issue
Block a user