From 463195fc177166462c78c8797addfd5c1b886053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Fri, 1 Apr 2022 16:51:40 +0100 Subject: [PATCH] fix: improve cashbox batches logs --- lib/cashbox-batches.js | 28 ++++++++++++++++++- .../graphql/resolvers/cashbox.resolver.js | 3 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/cashbox-batches.js b/lib/cashbox-batches.js index d5cd4e5c..e180fa37 100644 --- a/lib/cashbox-batches.js +++ b/lib/cashbox-batches.js @@ -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 } diff --git a/lib/new-admin/graphql/resolvers/cashbox.resolver.js b/lib/new-admin/graphql/resolvers/cashbox.resolver.js index acb29e93..193666c5 100644 --- a/lib/new-admin/graphql/resolvers/cashbox.resolver.js +++ b/lib/new-admin/graphql/resolvers/cashbox.resolver.js @@ -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),