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
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