feat: admin group edit / assign / unassign
This commit is contained in:
@@ -34,18 +34,19 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
GroupMutation: {
|
||||
assignUser(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)
|
||||
})
|
||||
})
|
||||
async assignUser(obj, args) {
|
||||
const grp = await WIKI.db.Group.findById(args.groupId)
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
const usr = await WIKI.db.User.findById(args.userId)
|
||||
if (!usr) {
|
||||
throw new gql.GraphQLError('Invalid User ID')
|
||||
}
|
||||
await grp.addUser(usr)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('User has been assigned to group.')
|
||||
}
|
||||
},
|
||||
async create(obj, args) {
|
||||
const group = await WIKI.db.Group.create({
|
||||
@@ -67,25 +68,29 @@ module.exports = {
|
||||
responseResult: graphHelper.generateSuccess('Group has been deleted.')
|
||||
}
|
||||
},
|
||||
unassignUser(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)
|
||||
})
|
||||
})
|
||||
async unassignUser(obj, args) {
|
||||
const grp = await WIKI.db.Group.findById(args.groupId)
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
const usr = await WIKI.db.User.findById(args.userId)
|
||||
if (!usr) {
|
||||
throw new gql.GraphQLError('Invalid User ID')
|
||||
}
|
||||
await grp.removeUser(usr)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('User has been unassigned from group.')
|
||||
}
|
||||
},
|
||||
update(obj, args) {
|
||||
return WIKI.db.Group.update({
|
||||
async update(obj, args) {
|
||||
await WIKI.db.Group.update({
|
||||
name: args.name
|
||||
}, {
|
||||
where: { id: args.id }
|
||||
})
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group has been updated.')
|
||||
}
|
||||
}
|
||||
},
|
||||
Group: {
|
||||
|
@@ -3,15 +3,42 @@
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
users(obj, args, context, info) {
|
||||
return WIKI.db.User.findAll({ where: args })
|
||||
}
|
||||
async users() { return {} }
|
||||
},
|
||||
Mutation: {
|
||||
createUser(obj, args) {
|
||||
async users() { return {} }
|
||||
},
|
||||
UserQuery: {
|
||||
async list(obj, args, context, info) {
|
||||
return WIKI.db.User.findAll({
|
||||
attributes: {
|
||||
exclude: ['password', 'tfaSecret']
|
||||
},
|
||||
raw: true
|
||||
})
|
||||
},
|
||||
async search(obj, args, context, info) {
|
||||
return WIKI.db.User.findAll({
|
||||
where: {
|
||||
$or: [
|
||||
{ email: { $like: `%${args.query}%` } },
|
||||
{ name: { $like: `%${args.query}%` } }
|
||||
]
|
||||
},
|
||||
limit: 10,
|
||||
attributes: ['id', 'email', 'name', 'provider', 'role', 'createdAt', 'updatedAt'],
|
||||
raw: true
|
||||
})
|
||||
},
|
||||
async single(obj, args, context, info) {
|
||||
return WIKI.db.User.findById(args.id)
|
||||
}
|
||||
},
|
||||
UserMutation: {
|
||||
create(obj, args) {
|
||||
return WIKI.db.User.create(args)
|
||||
},
|
||||
deleteUser(obj, args) {
|
||||
delete(obj, args) {
|
||||
return WIKI.db.User.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
@@ -19,7 +46,7 @@ module.exports = {
|
||||
limit: 1
|
||||
})
|
||||
},
|
||||
modifyUser(obj, args) {
|
||||
update(obj, args) {
|
||||
return WIKI.db.User.update({
|
||||
email: args.email,
|
||||
name: args.name,
|
||||
@@ -30,10 +57,10 @@ module.exports = {
|
||||
where: { id: args.id }
|
||||
})
|
||||
},
|
||||
resetUserPassword(obj, args) {
|
||||
resetPassword(obj, args) {
|
||||
return false
|
||||
},
|
||||
setUserPassword(obj, args) {
|
||||
setPassword(obj, args) {
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user