-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89e98fb
commit ba8de40
Showing
2 changed files
with
72 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,41 @@ | ||
const express = require('express') | ||
const _ = require('lodash/fp') | ||
const router = express.Router() | ||
|
||
const cashbox = require('../cashbox-batches') | ||
const notifier = require('../notifier') | ||
const { getMachine, setMachine } = require('../machine-loader') | ||
const { getMachine, setMachine, getMachineName } = require('../machine-loader') | ||
const { loadLatestConfig } = require('../new-settings-loader') | ||
const { getCashInSettings } = require('../new-config-manager') | ||
const { AUTOMATIC } = require('../constants') | ||
const logger = require('../logger') | ||
|
||
function notifyCashboxRemoval (req, res, next) { | ||
|
||
function cashboxRemoval (req, res, next) { | ||
const operatorId = res.locals.operatorId | ||
|
||
logger.info(`** DEBUG ** - Cashbox removal - Received a cashbox opening request from device ${req.deviceId}`) | ||
notifier.cashboxNotify(req.deviceId).catch(logger.error) | ||
|
||
return notifier.cashboxNotify(req.deviceId) | ||
.then(() => Promise.all([getMachine(req.deviceId), loadLatestConfig()])) | ||
return Promise.all([getMachine(req.deviceId), loadLatestConfig()]) | ||
.then(([machine, config]) => { | ||
logger.info('** DEBUG ** - Cashbox removal - Retrieving system options for cash-in') | ||
const cashInSettings = getCashInSettings(config) | ||
if (cashInSettings.cashboxReset !== AUTOMATIC) { | ||
logger.info('** DEBUG ** - Cashbox removal - Cashbox reset is set to manual. A cashbox batch will NOT be created') | ||
logger.info(`** DEBUG ** - Cashbox removal - Process finished`) | ||
return res.status(200).send({ status: 'OK' }) | ||
return Promise.all([ | ||
cashbox.getMachineUnbatchedBills(req.deviceId), | ||
getMachineName(req.deviceId) | ||
]) | ||
} | ||
logger.info('** DEBUG ** - Cashbox removal - Cashbox reset is set to automatic. A cashbox batch WILL be created') | ||
logger.info('** DEBUG ** - Cashbox removal - Creating new batch...') | ||
return cashbox.createCashboxBatch(req.deviceId, machine.cashUnits.cashbox) | ||
.then(() => { | ||
logger.info(`** DEBUG ** - Cashbox removal - Process finished`) | ||
return res.status(200).send({ status: 'OK' }) | ||
}) | ||
return cashbox.createCashboxBatch(req.deviceId, machine.cashbox) | ||
.then(batch => Promise.all([ | ||
cashbox.getBatchById(batch.id), | ||
getMachineName(batch.device_id), | ||
setMachine({ deviceId: req.deviceId, action: 'emptyCashInBills' }, operatorId) | ||
])) | ||
}) | ||
.then(([batch, machineName]) => res.status(200).send({ batch: _.merge(batch, { machineName }), status: 'OK' })) | ||
.catch(next) | ||
} | ||
|
||
router.post('/removal', notifyCashboxRemoval) | ||
router.post('/removal', cashboxRemoval) | ||
|
||
module.exports = router |