From 6fbb2b4c5b8306a167b5a53308503a1cbd8a3600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Wed, 10 May 2023 20:35:57 +0100 Subject: [PATCH] fix: stop trying to write to database when present with redundant empty and refill events --- lib/machine-loader.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/machine-loader.js b/lib/machine-loader.js index e5a933ac..009d262f 100644 --- a/lib/machine-loader.js +++ b/lib/machine-loader.js @@ -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'))