From b559434cbd5f165d70227c13d8efe98ee8fc28e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Thu, 9 Dec 2021 23:13:11 +0000 Subject: [PATCH] chore: simplify conditional --- lib/cashbox-batches.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/cashbox-batches.js b/lib/cashbox-batches.js index a6ce23d7..04294d33 100644 --- a/lib/cashbox-batches.js +++ b/lib/cashbox-batches.js @@ -20,7 +20,9 @@ function createCashboxBatch (deviceId, cashboxCount) { } function updateMachineWithBatch (machineContext, oldCashboxCount) { - if (!_.has(['deviceId', 'cashbox', 'cassettes'], machineContext) && !_.inRange(constants.CASH_OUT_MINIMUM_AMOUNT_OF_CASSETTES, constants.CASH_OUT_MAXIMUM_AMOUNT_OF_CASSETTES + 1, _.size(machineContext.cassettes))) + const isValidContext = _.has(['deviceId', 'cashbox', 'cassettes'], machineContext) + const isCassetteAmountWithinRange = _.inRange(constants.CASH_OUT_MINIMUM_AMOUNT_OF_CASSETTES, constants.CASH_OUT_MAXIMUM_AMOUNT_OF_CASSETTES + 1, _.size(machineContext.cassettes)) + if (!isValidContext && !isCassetteAmountWithinRange) throw new Error('Insufficient info to create a new cashbox batch') if (_.isEqual(0, oldCashboxCount)) throw new Error('Cashbox is empty. Cashbox batch could not be created.')