I need to make a query with pg-promise using the result to make 3 others queries but i am getting this error when executing:
Unhandled rejection TypeError: Method 'batch' requires an array of values. at batch (C:\apps\pfc\node_modules\spex\lib\ext\batch.js:61:26) at C:\apps\pfc\node_modules\spex\lib\ext\batch.js:149:26 at Task.batch (C:\apps\pfc\node_modules\pg-promise\lib\task.js:120:39)..............
This is my code:
db.task(t => {
return t.one('select gid, idgrupo from orden where gid = $1', req.params.ordenid, resultado => {
return t.batch([
t.one('select o.gid as num, v.matricula, v.denom, o.pkini, o.pkfin, o.fechaini, o.f_estimada, o.fechafin, o.idestado, o.descr, o.instr, g.id as idgrupo, g.nombre as grupo, g.actividad, e.descr as estado from orden as o inner join estado as e on o.idestado = e.gid inner join grupo as g on o.idgrupo = g.id inner join via as v on o.idctra = v.gid and o.gid = $1', resultado.gid),
t.any('select * from operacion order by gid where idgrupo = $1', resultado.idgrupo),
t.any('select m.gid, m.fechamed as fecha, m.cantidad, m.costemed as coste, o.codigo, o.descr from medicion m, operacion o where m.idorden = $1 and m.idope = o.gid order by fecha asc', resultado.gid)
])
.then(data => {
res.render('mediciones/nuevaMed', {
title: 'Crear / Modificar parte de trabajo',
orden: data[0],
operaciones: data[1],
medicion: [],
mediciones: data[2],
errors: []
});
}).catch(function(error) {next(error);});
}).then(t.batch);
});