lamassu-server/lib/new-admin/services/machines.js
Sérgio Salgado 15e0182ba1 fix: remove duplicated createBatch() calls
fix: rename cassetteMaxCapacity to snake uppercase
fix: notification module retrieving the wrong override fields
2021-12-02 14:37:11 +00:00

20 lines
826 B
JavaScript

const machineLoader = require('../../machine-loader')
const { UserInputError } = require('apollo-server-express')
function getMachine (machineId) {
return machineLoader.getMachines()
.then(machines => machines.find(({ deviceId }) => deviceId === machineId))
}
function machineAction ({ deviceId, action, cashbox, cassette1, cassette2, cassette3, cassette4, newName }, context) {
const operatorId = context.res.locals.operatorId
return getMachine(deviceId)
.then(machine => {
if (!machine) throw new UserInputError(`machine:${deviceId} not found`, { deviceId })
return machine
})
.then(machineLoader.setMachine({ deviceId, action, cashbox, cassettes: [cassette1, cassette2, cassette3, cassette4], newName }, operatorId))
.then(getMachine(deviceId))
}
module.exports = { machineAction }