From 025877355d9589e46b70b5c4d54e7633ec2c18d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20D=C4=99bski?= Date: Wed, 7 Nov 2018 15:35:33 +0100 Subject: [PATCH] Added poolsUpdate to API --- .../graphqlModules/Pool/PoolsUpdate.js | 31 +++++++++++++++++++ src/store/api/pools/collection/poolsUpdate.js | 8 +++++ src/store/api/pools/poolsUpdate.js | 9 ++++++ 3 files changed, 48 insertions(+) create mode 100644 src/graphql/graphqlModules/Pool/PoolsUpdate.js create mode 100644 src/store/api/pools/collection/poolsUpdate.js create mode 100644 src/store/api/pools/poolsUpdate.js diff --git a/src/graphql/graphqlModules/Pool/PoolsUpdate.js b/src/graphql/graphqlModules/Pool/PoolsUpdate.js new file mode 100644 index 0000000..9153624 --- /dev/null +++ b/src/graphql/graphqlModules/Pool/PoolsUpdate.js @@ -0,0 +1,31 @@ +module.exports.typeDefs = ` + type PoolActions { + updateAll (input: [PoolsUpdateInput!]!): PoolsUpdateOutput! + } + + input PoolsUpdateInput { + index: Int! + enabled: Boolean! + url: String! + username: String + password: String + proxy: String + } + + type PoolsUpdateOutput { + result: PoolsUpdateResult + error: Error + } + + type PoolsUpdateResult { + pools: [Pool!]! + } +` + +module.exports.resolvers = { + PoolActions: { + updateAll (root, args, { dispatch }) { + return dispatch('api/pools/updateAll', args.input) + } + } +} \ No newline at end of file diff --git a/src/store/api/pools/collection/poolsUpdate.js b/src/store/api/pools/collection/poolsUpdate.js new file mode 100644 index 0000000..afb3b31 --- /dev/null +++ b/src/store/api/pools/collection/poolsUpdate.js @@ -0,0 +1,8 @@ +module.exports = ({ define }) => { + define('updateAll', async (data = {}, { dispatch, knex, errors, utils }) => { + return await knex.transaction(async function(trx) { + await trx.delete().from('pools') + await trx.insert(data).into('pools') + }); + }) +} diff --git a/src/store/api/pools/poolsUpdate.js b/src/store/api/pools/poolsUpdate.js new file mode 100644 index 0000000..8a5e9db --- /dev/null +++ b/src/store/api/pools/poolsUpdate.js @@ -0,0 +1,9 @@ +module.exports = ({ define }) => { + define('updateAll', async (payload, { dispatch, errors, utils }) => { + await dispatch('api/pools/collection/updateAll', payload) + const { items: pools } = await dispatch('api/pools/collection/read', {}) + return { + pools + } + }) +}