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
|
|
@ -173,6 +173,42 @@ function setCassetteBills (rec) {
|
|||
})
|
||||
}
|
||||
|
||||
function emptyMachineUnits (deviceId, units) {
|
||||
return Promise.all([getMachine(deviceId), configManager.getCashOut(deviceId, getConfig())])
|
||||
.then(([machine, cashoutSettings]) => {
|
||||
const movedBills = _.reduce(
|
||||
(acc, value) => ({
|
||||
...acc,
|
||||
[value]: {
|
||||
delta: machine[value] - units[value],
|
||||
denomination: cashoutSettings[value]
|
||||
}
|
||||
}),
|
||||
{},
|
||||
_.keys(units)
|
||||
)
|
||||
|
||||
const sql = `UPDATE devices SET cassette1=$2, cassette2=$3, cassette3=$4, cassette4=$5, stacker1f=$6, stacker1r=$7, stacker2f=$8, stacker2r=$9, stacker3f=$10, stacker3r=$11 WHERE device_id=$1`
|
||||
return db.none(sql, [
|
||||
deviceId,
|
||||
_.defaultTo(0, units.cassette1),
|
||||
_.defaultTo(0, units.cassette2),
|
||||
_.defaultTo(0, units.cassette3),
|
||||
_.defaultTo(0, units.cassette4),
|
||||
_.defaultTo(0, units.stacker1f),
|
||||
_.defaultTo(0, units.stacker1r),
|
||||
_.defaultTo(0, units.stacker2f),
|
||||
_.defaultTo(0, units.stacker2r),
|
||||
_.defaultTo(0, units.stacker3f),
|
||||
_.defaultTo(0, units.stacker3r)
|
||||
])
|
||||
})
|
||||
}
|
||||
|
||||
function refillMachineUnits (deviceId, units) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
function unpair (rec) {
|
||||
return pairing.unpair(rec.deviceId)
|
||||
}
|
||||
|
|
@ -204,6 +240,24 @@ function restartServices (rec) {
|
|||
)])
|
||||
}
|
||||
|
||||
function emptyUnit (rec) {
|
||||
return db.none('NOTIFY $1:name, $2', ['machineAction', JSON.stringify(
|
||||
{
|
||||
action: 'emptyUnit',
|
||||
value: _.pick(['deviceId', 'operatorId', 'action'], rec)
|
||||
}
|
||||
)])
|
||||
}
|
||||
|
||||
function refillUnit (rec) {
|
||||
return db.none('NOTIFY $1:name, $2', ['machineAction', JSON.stringify(
|
||||
{
|
||||
action: 'refillUnit',
|
||||
value: _.pick(['deviceId', 'operatorId', 'action'], rec)
|
||||
}
|
||||
)])
|
||||
}
|
||||
|
||||
function setMachine (rec, operatorId) {
|
||||
rec.operatorId = operatorId
|
||||
switch (rec.action) {
|
||||
|
|
@ -215,6 +269,8 @@ function setMachine (rec, operatorId) {
|
|||
case 'reboot': return reboot(rec)
|
||||
case 'shutdown': return shutdown(rec)
|
||||
case 'restartServices': return restartServices(rec)
|
||||
case 'emptyUnit': return emptyUnit(rec)
|
||||
case 'refillUnit': return refillUnit(rec)
|
||||
default: throw new Error('No such action: ' + rec.action)
|
||||
}
|
||||
}
|
||||
|
|
@ -288,5 +344,7 @@ module.exports = {
|
|||
updateNetworkHeartbeat,
|
||||
getNetworkPerformance,
|
||||
getNetworkHeartbeat,
|
||||
getConfig
|
||||
getConfig,
|
||||
emptyMachineUnits,
|
||||
refillMachineUnits
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue