lamassu-server/lib/new-admin/machines.js
Mauricio Navarro Miranda fdf18b60ad feat: add machine status page (#344)
* feat: add confirm-dialog component

* feat: add MachineStatus to router

* feat: add machine details to api endpoints

* feat: add machine-status expandabletable

* fix: add missing property to TextInput on story

* style: minor style fixes

* feat: useAxios to unpair and reboot specific machinees

* fix: style fixes
use shutdown instead of reboot
use named colors

* fix: use new ExpTable

* fix: class instead of sttyles, use named colors

* feat: use ConfirmDialog to confirm unpair action

* chore: eslint fix

* refactor: use gql, new ExpTable and ramda on machine-status

* fix: 'fallback' status instead of the 'all good' one

* fix: makeStyles instead of withStyles

* refactor: simplify StatusChip

* fix: css spacing instead of nbsp

* fix: move makeStyles outside component

* refactor: makeStyles instead of withStyles

* refactor: adapting based props for Status

* refactor: moar simple Status chip

* feat: use graphql mutation instead of rest for machine action
feat: use graphql instead of rest on MachineDetailsCard

* fix: Dialog close must be handled outside

* fix: just pass down onDissmissed and onConfirmed to the component
https://github.com/lamassu/lamassu-server/pull/344#discussion_r370136028

* refactor: machineAction on separate file and 404 handling

* feat: basic handling of graphql exceptions on machineAction
2020-02-04 21:12:44 +01:00

20 lines
649 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 }) {
return getMachine(deviceId)
.then(machine => {
if (!machine) throw new UserInputError(`machine:${deviceId} not found`, { deviceId })
return machine
})
.then(machineLoader.setMachine({ deviceId, action }))
.then(getMachine(deviceId))
}
module.exports = { machineAction }