chore: simplify conditional

This commit is contained in:
Sérgio Salgado 2021-12-09 23:13:11 +00:00
parent f16be1d263
commit b559434cbd

View file

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