refactor: inline one step
This commit is contained in:
parent
347844610c
commit
d47101215f
1 changed files with 7 additions and 9 deletions
|
|
@ -161,20 +161,18 @@ function plugins (settings, deviceId) {
|
||||||
return _.map(([acc, bill]) => acc + bill.provisioned, _.zip(sum, bills))
|
return _.map(([acc, bill]) => acc + bill.provisioned, _.zip(sum, bills))
|
||||||
}
|
}
|
||||||
|
|
||||||
const counts = _.flow(
|
recyclers = _.flow(
|
||||||
|
// Sum "used" bills per recycler
|
||||||
_.reduce(sumTxs, _.map(_.constant(0), recyclers)),
|
_.reduce(sumTxs, _.map(_.constant(0), recyclers)),
|
||||||
_.zip(_.map('count', recyclers)),
|
_.zip(recyclers),
|
||||||
_.map(([count, provisioned]) => count - provisioned),
|
// Remove used bills from recycler counts
|
||||||
|
_.map(([recycler, provisioned]) => _.set('count', recycler.count - provisioned, recycler)),
|
||||||
)(redeemableTxs)
|
)(redeemableTxs)
|
||||||
|
|
||||||
if (_.some(_.lt(_, 0), counts)) {
|
if (_.some(({ count }) => count < 0, recyclers))
|
||||||
throw new Error('Negative note count: %j', counts)
|
throw new Error('Negative note count: %j', counts)
|
||||||
}
|
|
||||||
|
|
||||||
return _.map(
|
return recyclers
|
||||||
recycler => _.set('count', counts[recycler.number], recycler),
|
|
||||||
recyclers
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildAvailableCassettes (excludeTxId) {
|
function buildAvailableCassettes (excludeTxId) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue