Added poolsUpdate to API

This commit is contained in:
Jakub Dębski 2018-11-07 15:35:33 +01:00
parent ace08c7167
commit 025877355d
3 changed files with 48 additions and 0 deletions

View File

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

View File

@ -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')
});
})
}

View File

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