feat: add cashbox batches log downloader

This commit is contained in:
Sérgio Salgado 2022-03-29 22:50:34 +01:00
parent b8ae64a798
commit f2f34c6ecd
8 changed files with 60 additions and 30 deletions

View file

@ -47,15 +47,16 @@ function updateMachineWithBatch (machineContext, oldCashboxCount) {
})
}
function getBatches () {
function getBatches (from = new Date(0).toISOString(), until = new Date().toISOString()) {
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
WHERE cb.created >= $1 AND cb.created <= $2
GROUP BY cb.id
ORDER BY cb.created DESC
`
return db.any(sql).then(res => _.map(it => _.mapKeys(ite => _.camelCase(ite), it), res))
return db.any(sql, [from, until]).then(res => _.map(it => _.mapKeys(ite => _.camelCase(ite), it), res))
}
function editBatchById (id, performedBy) {