fix: Corregir funciones json_agg y json_build_object en PostgreSQL para pre-órdenes y escaneo QR

This commit is contained in:
unknown
2026-10-05 05:18:13 -06:00
parent 96c789edac
commit 7cd5c3b6ab
3 changed files with 19 additions and 4 deletions
+4
View File
@@ -32,6 +32,10 @@ if (isPg) {
s = s.replace(/date\s*\(\s*['"]now['"][^)]*\)/gi, 'CURRENT_DATE');
s = s.replace(/date\s*\(\s*([^,)]+)(?:\s*,\s*['"]localtime['"])?\s*\)/gi, 'CAST($1 AS DATE)');
// Compatibilidad SQLite -> PostgreSQL para funciones JSON
s = s.replace(/json_group_array\s*\(/gi, 'json_agg(');
s = s.replace(/json_object\s*\(/gi, 'json_build_object(');
return s;
}
+6 -2
View File
@@ -1397,7 +1397,9 @@ app.get('/api/estudiantes/qr/:token', (req, res) => {
const preordenesFormateadas = preordenesPendientes.map(o => ({
...o,
items: JSON.parse(o.items_json || '[]')
items: Array.isArray(o.items_json)
? o.items_json
: (typeof o.items_json === 'string' ? JSON.parse(o.items_json || '[]') : [])
}));
res.json({
@@ -1687,7 +1689,9 @@ app.get('/api/ordenes', (req, res) => {
const ordenes = db.prepare(query).all(...params);
const resultado = ordenes.map(o => ({
...o,
items: JSON.parse(o.items_json || '[]')
items: Array.isArray(o.items_json)
? o.items_json
: (typeof o.items_json === 'string' ? JSON.parse(o.items_json || '[]') : [])
}));
res.json(resultado);