fix: Corregir funciones json_agg y json_build_object en PostgreSQL para pre-órdenes y escaneo QR
This commit is contained in:
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user