fix: improve cashbox batches logs

This commit is contained in:
Sérgio Salgado 2022-04-01 16:51:40 +01:00
parent 1d5b758e39
commit 463195fc17
2 changed files with 29 additions and 2 deletions

View file

@ -69,10 +69,36 @@ function getBillsByBatchId (id) {
return db.any(sql, [id])
}
function logFormatter (data) {
return _.map(
it => {
return {
id: it.id,
deviceId: it.deviceId,
created: it.created,
operationType: it.operationType,
performedBy: it.performedBy,
billCount: _.size(it.bills),
fiatTotals: _.reduce(
(acc, value) => {
acc[value.fiat_code] = (acc[value.fiat_code] || 0) + value.fiat
return acc
},
{},
it.bills
),
billsByDenomination: _.countBy(ite => `${ite.fiat} ${ite.fiat_code}`, it.bills)
}
},
data
)
}
module.exports = {
createCashboxBatch,
updateMachineWithBatch,
getBatches,
getBillsByBatchId,
editBatchById
editBatchById,
logFormatter
}