Merge pull request #1182 from chaotixkilla/fix-improve-cashbox-batches-logs

Improve cashbox batches logs
This commit is contained in:
Rafael Taranto 2022-04-01 19:25:10 +01:00 committed by GitHub
commit 03cb4a3c4c
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
}

View file

@ -5,7 +5,8 @@ const logDateFormat = require('../../../logs').logDateFormat
const resolvers = {
Query: {
cashboxBatches: () => cashbox.getBatches(),
cashboxBatchesCsv: (...[, { from, until, timezone }]) => cashbox.getBatches(from, until).then(data => parseAsync(logDateFormat(timezone, data, ['created'])))
cashboxBatchesCsv: (...[, { from, until, timezone }]) => cashbox.getBatches(from, until)
.then(data => parseAsync(logDateFormat(timezone, cashbox.logFormatter(data), ['created'])))
},
Mutation: {
createBatch: (...[, { deviceId, cashboxCount }]) => cashbox.createCashboxBatch(deviceId, cashboxCount),