feat: GraphQL mutations for folder, group, tag, user

This commit is contained in:
NGPixel
2017-08-13 20:33:06 -04:00
parent 1405b822f4
commit 840eb7e705
9 changed files with 163 additions and 5 deletions
+36
View File
@@ -2,6 +2,8 @@
/* global wiki */
const gql = require('graphql')
module.exports = {
Query: {
groups(obj, args, context, info) {
@@ -9,8 +11,42 @@ module.exports = {
}
},
Mutation: {
assignUserToGroup(obj, args) {
return wiki.db.Group.findById(args.groupId).then(grp => {
if (!grp) {
throw new gql.GraphQLError('Invalid Group ID')
}
return wiki.db.User.findById(args.userId).then(usr => {
if (!usr) {
throw new gql.GraphQLError('Invalid User ID')
}
return grp.addUser(usr)
})
})
},
createGroup(obj, args) {
return wiki.db.Group.create(args)
},
deleteGroup(obj, args) {
return wiki.db.Group.destroy({
where: {
id: args.id
},
limit: 1
})
},
removeUserFromGroup(obj, args) {
return wiki.db.Group.findById(args.groupId).then(grp => {
if (!grp) {
throw new gql.GraphQLError('Invalid Group ID')
}
return wiki.db.User.findById(args.userId).then(usr => {
if (!usr) {
throw new gql.GraphQLError('Invalid User ID')
}
return grp.removeUser(usr)
})
})
}
},
Group: {