lamassu-server/packages/server/lib/new-admin/services/machines.js
2025-05-12 15:35:00 +01:00

27 lines
774 B
JavaScript

const machineLoader = require('../../machine-loader')
const { UserInputError } = require('../graphql/errors')
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 }