feat: add unpaired machines endpoint to GraphQL

This commit is contained in:
André Sá 2022-03-11 15:13:08 +00:00
parent 986df24864
commit 0f93e313b6
3 changed files with 23 additions and 1 deletions

View file

@ -43,6 +43,16 @@ function getMachines () {
.then(rr => rr.map(toMachineObject)) .then(rr => rr.map(toMachineObject))
} }
function getUnpairedMachines () {
return db.any('SELECT * FROM unpaired_devices')
.then(_.map(r =>
_.flow(
_.set('deviceId', _.get('device_id', r)),
_.unset('device_id')
)(r)
))
}
function getConfig (defaultConfig) { function getConfig (defaultConfig) {
if (defaultConfig) return Promise.resolve(defaultConfig) if (defaultConfig) return Promise.resolve(defaultConfig)
@ -257,6 +267,7 @@ function getNetworkHeartbeatByDevice (deviceId) {
module.exports = { module.exports = {
getMachineName, getMachineName,
getMachines, getMachines,
getUnpairedMachines,
getMachine, getMachine,
getMachineNames, getMachineNames,
setMachine, setMachine,

View file

@ -15,7 +15,8 @@ const resolvers = {
}, },
Query: { Query: {
machines: () => machineLoader.getMachineNames(), machines: () => machineLoader.getMachineNames(),
machine: (...[, { deviceId }]) => machineLoader.getMachine(deviceId) machine: (...[, { deviceId }]) => machineLoader.getMachine(deviceId),
unpairedMachines: () => machineLoader.getUnpairedMachines()
}, },
Mutation: { Mutation: {
machineAction: (...[, { deviceId, action, cashbox, cassette1, cassette2, cassette3, cassette4, newName }, context]) => machineAction: (...[, { deviceId, action, cashbox, cassette1, cassette2, cassette3, cassette4, newName }, context]) =>

View file

@ -27,6 +27,15 @@ const typeDef = gql`
packetLoss: String packetLoss: String
} }
type UnpairedMachine {
id: ID!
deviceId: ID!
name: String
model: String
paired: Date!
unpaired: Date!
}
type MachineEvent { type MachineEvent {
id: ID id: ID
deviceId: String deviceId: String
@ -51,6 +60,7 @@ const typeDef = gql`
type Query { type Query {
machines: [Machine] @auth machines: [Machine] @auth
machine(deviceId: ID!): Machine @auth machine(deviceId: ID!): Machine @auth
unpairedMachines: [UnpairedMachine!]! @auth
} }
type Mutation { type Mutation {