lamassu-server/lib/new-admin/services/machines.js
Sérgio Salgado 211c4b1ea7 feat: add aveiro cash units to the devices table
feat: change data fetching to accomodate the new cash units
2023-06-07 14:27:42 +01:00

20 lines
729 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, cashUnits, 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, cashUnits, newName }, operatorId))
.then(getMachine(deviceId))
}
module.exports = { machineAction }