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.')