refactor: simplify buildAvailableCassettes similarly to buildAvailableRecyclers
This commit is contained in:
parent
f2d07c8cc7
commit
02cfe7530b
1 changed files with 14 additions and 17 deletions
|
|
@ -153,30 +153,27 @@ function plugins (settings, deviceId) {
|
||||||
if (!cashOutConfig.active) return Promise.resolve()
|
if (!cashOutConfig.active) return Promise.resolve()
|
||||||
|
|
||||||
return Promise.all([dbm.cassetteCounts(deviceId), cashOutHelper.redeemableTxs(deviceId, excludeTxId)])
|
return Promise.all([dbm.cassetteCounts(deviceId), cashOutHelper.redeemableTxs(deviceId, excludeTxId)])
|
||||||
.then(([_cassettes, _redeemableTxs]) => {
|
.then(([{ counts, numberOfCassettes }, redeemableTxs]) => {
|
||||||
const redeemableTxs = _.reject(_.matchesProperty('id', excludeTxId), _redeemableTxs)
|
redeemableTxs = _.reject(_.matchesProperty('id', excludeTxId), redeemableTxs)
|
||||||
|
|
||||||
const denominations = []
|
const denominations = _.map(
|
||||||
_.forEach(it => {
|
it => cashOutConfig[`cassette${it}`],
|
||||||
denominations.push(cashOutConfig[`cassette${it + 1}`])
|
_.range(1, numberOfCassettes+1)
|
||||||
}, _.times(_.identity(), _cassettes.numberOfCassettes))
|
)
|
||||||
|
|
||||||
const virtualCassettes = denominations.length ? [Math.max(...denominations) * 2] : []
|
if (counts.length !== denominations.length)
|
||||||
|
|
||||||
const counts = _cassettes.counts
|
|
||||||
|
|
||||||
if (counts.length !== denominations.length) {
|
|
||||||
throw new Error('Denominations and respective counts do not match!')
|
throw new Error('Denominations and respective counts do not match!')
|
||||||
}
|
|
||||||
|
|
||||||
const cassettes = []
|
const cassettes = _.map(
|
||||||
_.forEach(it => {
|
it => ({
|
||||||
cassettes.push({
|
|
||||||
name: `cassette${it + 1}`,
|
name: `cassette${it + 1}`,
|
||||||
denomination: parseInt(denominations[it], 10),
|
denomination: parseInt(denominations[it], 10),
|
||||||
count: parseInt(counts[it], 10)
|
count: parseInt(counts[it], 10)
|
||||||
})
|
}),
|
||||||
}, _.times(_.identity(), _cassettes.numberOfCassettes))
|
_.range(0, numberOfCassettes)
|
||||||
|
)
|
||||||
|
|
||||||
|
const virtualCassettes = denominations.length ? [Math.max(...denominations) * 2] : []
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue