fix: cashbox batches log possible NaN and null values

This commit is contained in:
Sérgio Salgado 2022-04-04 17:04:37 +01:00
parent 03cb4a3c4c
commit 24807a70ef

View file

@ -72,22 +72,25 @@ function getBillsByBatchId (id) {
function logFormatter (data) { function logFormatter (data) {
return _.map( return _.map(
it => { it => {
const bills = _.filter(
ite => !(_.isNil(ite) || _.isNil(ite.fiat_code) || _.isNil(ite.fiat) || _.isNaN(ite.fiat)),
it.bills
)
return { return {
id: it.id, id: it.id,
deviceId: it.deviceId, deviceId: it.deviceId,
created: it.created, created: it.created,
operationType: it.operationType, operationType: it.operationType,
performedBy: it.performedBy, billCount: _.size(bills),
billCount: _.size(it.bills),
fiatTotals: _.reduce( fiatTotals: _.reduce(
(acc, value) => { (acc, value) => {
acc[value.fiat_code] = (acc[value.fiat_code] || 0) + value.fiat acc[value.fiat_code] = (acc[value.fiat_code] || 0) + value.fiat
return acc return acc
}, },
{}, {},
it.bills bills
), ),
billsByDenomination: _.countBy(ite => `${ite.fiat} ${ite.fiat_code}`, it.bills) billsByDenomination: _.countBy(ite => `${ite.fiat} ${ite.fiat_code}`, bills)
} }
}, },
data data