fix: stop trying to write to database when present with redundant empty and refill events

This commit is contained in:
Sérgio Salgado 2023-05-10 20:35:57 +01:00
parent 9f2a29d5a7
commit 6fbb2b4c5b

View file

@ -213,6 +213,11 @@ function emptyMachineUnits ({ deviceId, newUnits, fiatCode }) {
_.keys(_.omit(['cashbox'], movedBills))
)
// This occurs when an empty unit is called when the units are already empty, hence, no bills moved around
if (_.isEmpty(billArr) && _.isEmpty(operationsToCreate)) {
return Promise.resolve()
}
return db.tx(t => {
const q1Cols = ['id', 'device_id', 'operation_type']
const q1= t.none(pgp.helpers.insert(operationsToCreate, q1Cols, 'cash_unit_operation'))
@ -260,6 +265,11 @@ function refillMachineUnits ({ deviceId, newUnits }) {
operation_type: it
}))(operationNames)
// This occurs when a refill unit is called when the loading boxes are empty, hence, no bills moved around
if (_.isEmpty(operationsToCreate)) {
return Promise.resolve()
}
return db.tx(t => {
const q1Cols = ['id', 'device_id', 'operation_type']
const q1= t.none(pgp.helpers.insert(operationsToCreate, q1Cols, 'cash_unit_operation'))