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 + } + }) +}