2017-08-07 01:05:10 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
/* global wiki */
|
|
|
|
|
2017-08-14 00:33:06 +00:00
|
|
|
const gql = require('graphql')
|
|
|
|
|
2017-08-07 01:05:10 +00:00
|
|
|
module.exports = {
|
2017-08-09 02:36:29 +00:00
|
|
|
Query: {
|
|
|
|
groups(obj, args, context, info) {
|
|
|
|
return wiki.db.Group.findAll({ where: args })
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Mutation: {
|
2017-08-14 00:33:06 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
2017-08-09 02:36:29 +00:00
|
|
|
createGroup(obj, args) {
|
|
|
|
return wiki.db.Group.create(args)
|
2017-08-14 00:33:06 +00:00
|
|
|
},
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|
2017-08-20 02:51:25 +00:00
|
|
|
},
|
|
|
|
renameGroup(obj, args) {
|
|
|
|
return wiki.db.Group.update({
|
|
|
|
name: args.name
|
|
|
|
}, {
|
|
|
|
where: { id: args.id }
|
|
|
|
})
|
2017-08-09 02:36:29 +00:00
|
|
|
}
|
2017-08-07 01:05:10 +00:00
|
|
|
},
|
2017-08-09 02:36:29 +00:00
|
|
|
Group: {
|
2017-08-07 01:05:10 +00:00
|
|
|
users(grp) {
|
|
|
|
return grp.getUsers()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|