feat: add empty and refill unit machine actions
fix: remove certain actions from the state middleware after being consumed by the poller
This commit is contained in:
parent
2e9bb3c7df
commit
797f074898
10 changed files with 163 additions and 2 deletions
|
|
@ -96,6 +96,8 @@ function poll (req, res, next) {
|
|||
const reboot = pid && state.reboots?.[operatorId]?.[deviceId] === pid
|
||||
const shutdown = pid && state.shutdowns?.[operatorId]?.[deviceId] === pid
|
||||
const restartServices = pid && state.restartServicesMap?.[operatorId]?.[deviceId] === pid
|
||||
const emptyUnit = pid && state.emptyUnit?.[operatorId]?.[deviceId] === pid
|
||||
const refillUnit = pid && state.refillUnit?.[operatorId]?.[deviceId] === pid
|
||||
const langs = localeConfig.languages
|
||||
|
||||
const locale = {
|
||||
|
|
@ -119,6 +121,8 @@ function poll (req, res, next) {
|
|||
reboot,
|
||||
shutdown,
|
||||
restartServices,
|
||||
emptyUnit,
|
||||
refillUnit,
|
||||
hasLightning,
|
||||
receipt,
|
||||
operatorInfo,
|
||||
|
|
|
|||
34
lib/routes/unitsRoutes.js
Normal file
34
lib/routes/unitsRoutes.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
const express = require('express')
|
||||
const { emptyMachineUnits, refillMachineUnits } = require('../machine-loader')
|
||||
const router = express.Router()
|
||||
|
||||
const emptyUnitUpdateCounts = (req, res, next) => {
|
||||
const deviceId = req.deviceId
|
||||
const newUnits = req.body.newUnits
|
||||
|
||||
return emptyMachineUnits({ deviceId, cashUnits: newUnits })
|
||||
.then(() => res.sendStatus(200))
|
||||
.catch(e => {
|
||||
console.error(e)
|
||||
return res.sendStatus(500)
|
||||
})
|
||||
.finally(next)
|
||||
}
|
||||
|
||||
const refillUnitUpdateCounts = (req, res, next) => {
|
||||
const deviceId = req.deviceId
|
||||
const newUnits = req.body.newUnits
|
||||
|
||||
return refillMachineUnits({ deviceId, cashUnits: newUnits })
|
||||
.then(() => res.sendStatus(200))
|
||||
.catch(e => {
|
||||
console.error(e)
|
||||
return res.sendStatus(500)
|
||||
})
|
||||
.finally(next)
|
||||
}
|
||||
|
||||
router.post('/empty', emptyUnitUpdateCounts)
|
||||
router.post('/refill', refillUnitUpdateCounts)
|
||||
|
||||
module.exports = router
|
||||
Loading…
Add table
Add a link
Reference in a new issue