refactor: use promise all
This commit is contained in:
parent
ad30468708
commit
686c7a2b36
2 changed files with 16 additions and 13 deletions
|
|
@ -5,20 +5,18 @@ const cashbox = require('../cashbox-batches')
|
|||
const { getMachine, setMachine } = require('../machine-loader')
|
||||
const { loadLatestConfig } = require('../new-settings-loader')
|
||||
const { getCashInSettings } = require('../new-config-manager')
|
||||
const { AUTOMATIC } = require('../constants.js')
|
||||
|
||||
function notifyCashboxRemoval (req, res, next) {
|
||||
return getMachine(req.deviceId)
|
||||
.then(machine => {
|
||||
loadLatestConfig()
|
||||
.then(config => {
|
||||
const cashInSettings = getCashInSettings(config)
|
||||
if (cashInSettings.cashboxReset === 'Automatic') {
|
||||
return cashbox.createCashboxBatch(req.deviceId, machine.cashbox)
|
||||
.then(() => setMachine({ deviceId: req.deviceId, action: 'emptyCashInBills' }))
|
||||
.then(() => res.status(200).send({ status: 'OK' }))
|
||||
}
|
||||
return res.status(200).send({ status: 'OK' })
|
||||
})
|
||||
return Promise.all([getMachine(req.deviceId), loadLatestConfig()])
|
||||
.then(([machine, config]) => {
|
||||
const cashInSettings = getCashInSettings(config)
|
||||
if (cashInSettings.cashboxReset !== AUTOMATIC) {
|
||||
return res.status(200).send({ status: 'OK' })
|
||||
}
|
||||
return cashbox.createCashboxBatch(req.deviceId, machine.cashbox)
|
||||
.then(() => setMachine({ deviceId: req.deviceId, action: 'emptyCashInBills' }))
|
||||
.then(() => res.status(200).send({ status: 'OK' }))
|
||||
})
|
||||
.catch(next)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue