lamassu-server/lib/new-admin/machines.js
Liordino Neto bbf98b4d52 feat: created the rename action on the machine status page
fix: added missing 'shutdown' action on the MachineActions enum of the
gql schema

style: set the Edit icon for the rename action

style: fixed first and last action buttons spacing
2020-10-15 21:20:06 +02:00

19 lines
689 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, cassette1, cassette2, newName }) {
return getMachine(deviceId)
.then(machine => {
if (!machine) throw new UserInputError(`machine:${deviceId} not found`, { deviceId })
return machine
})
.then(machineLoader.setMachine({ deviceId, action, cassettes: [cassette1, cassette2], newName }))
.then(getMachine(deviceId))
}
module.exports = { machineAction }