fix: sort cashbox batches by date

This commit is contained in:
André Sá 2021-11-18 17:59:22 +00:00
parent 8128f05ffb
commit d30c381674

View file

@ -19,8 +19,13 @@ function createCashboxBatch (deviceId, cashboxCount) {
}
function getBatches () {
const sql = `SELECT cb.id, cb.device_id, cb.created, cb.operation_type, cb.bill_count_override, cb.performed_by,
json_agg(b.*) AS bills FROM cashbox_batches cb LEFT JOIN bills b ON cb.id=b.cashbox_batch_id GROUP BY cb.id`
const sql = `
SELECT cb.id, cb.device_id, cb.created, cb.operation_type, cb.bill_count_override, cb.performed_by, json_agg(b.*) AS bills
FROM cashbox_batches AS cb
LEFT JOIN bills AS b ON cb.id = b.cashbox_batch_id
GROUP BY cb.id
ORDER BY cb.created DESC
`
return db.any(sql).then(res => _.map(it => _.mapKeys(ite => _.camelCase(ite), it), res))
}