From 8b983c78267ff61f7ad2865c69cd8e741f636bac Mon Sep 17 00:00:00 2001 From: Aleksander Barszczewski Date: Thu, 25 Oct 2018 15:26:46 +0200 Subject: [PATCH] mcu api --- src/graphql/graphqlModules/Mcu/Mcu.js | 13 +++++++++++++ src/graphql/graphqlModules/Mcu/McuReboot.js | 13 +++++++++++++ src/graphql/graphqlModules/Mcu/McuShutdown.js | 13 +++++++++++++ src/store/api/mcu/mcuReboot.js | 7 +++++++ src/store/api/mcu/mcuShutdown.js | 7 +++++++ 5 files changed, 53 insertions(+) create mode 100644 src/graphql/graphqlModules/Mcu/Mcu.js create mode 100644 src/graphql/graphqlModules/Mcu/McuReboot.js create mode 100644 src/graphql/graphqlModules/Mcu/McuShutdown.js create mode 100644 src/store/api/mcu/mcuReboot.js create mode 100644 src/store/api/mcu/mcuShutdown.js diff --git a/src/graphql/graphqlModules/Mcu/Mcu.js b/src/graphql/graphqlModules/Mcu/Mcu.js new file mode 100644 index 0000000..dad3cdc --- /dev/null +++ b/src/graphql/graphqlModules/Mcu/Mcu.js @@ -0,0 +1,13 @@ +module.exports.typeDefs = ` + type Query { + Mcu: McuActions + } +` + +module.exports.resolvers = { + Query: { + Mcu () { + return {} + } + } +} diff --git a/src/graphql/graphqlModules/Mcu/McuReboot.js b/src/graphql/graphqlModules/Mcu/McuReboot.js new file mode 100644 index 0000000..ac1ac87 --- /dev/null +++ b/src/graphql/graphqlModules/Mcu/McuReboot.js @@ -0,0 +1,13 @@ +module.exports.typeDefs = ` + type McuActions { + reboot: EmptyOutput! + } +` + +module.exports.resolvers = { + McuActions: { + reboot (root, args, { dispatch }) { + return dispatch('api/mcu/reboot') + } + } +} diff --git a/src/graphql/graphqlModules/Mcu/McuShutdown.js b/src/graphql/graphqlModules/Mcu/McuShutdown.js new file mode 100644 index 0000000..2cf2b7d --- /dev/null +++ b/src/graphql/graphqlModules/Mcu/McuShutdown.js @@ -0,0 +1,13 @@ +module.exports.typeDefs = ` + type McuActions { + shutdown: EmptyOutput! + } +` + +module.exports.resolvers = { + McuActions: { + shutdown (root, args, { dispatch }) { + return dispatch('api/mcu/shutdown') + } + } +} diff --git a/src/store/api/mcu/mcuReboot.js b/src/store/api/mcu/mcuReboot.js new file mode 100644 index 0000000..a6acc46 --- /dev/null +++ b/src/store/api/mcu/mcuReboot.js @@ -0,0 +1,7 @@ +const { exec } = require('child_process') + +module.exports = ({ define }) => { + define('reboot', async (payload, { knex, errors, utils }) => { + exec('shutdown -r now') + }) +} diff --git a/src/store/api/mcu/mcuShutdown.js b/src/store/api/mcu/mcuShutdown.js new file mode 100644 index 0000000..d348527 --- /dev/null +++ b/src/store/api/mcu/mcuShutdown.js @@ -0,0 +1,7 @@ +const { exec } = require('child_process') + +module.exports = ({ define }) => { + define('shutdown', async (payload, { knex, errors, utils }) => { + exec('shutdown now') + }) +}