fix: prevent duplicate group assignment (#1081)

This commit is contained in:
Nicolas Giard 2019-10-14 23:56:37 -04:00 committed by GitHub
parent cffd32dee0
commit c5ce6bcbaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,6 +34,13 @@ module.exports = {
if (!usr) { if (!usr) {
throw new gql.GraphQLError('Invalid User ID') throw new gql.GraphQLError('Invalid User ID')
} }
const relExist = await WIKI.models.knex('userGroups').where({
userId: args.userId,
groupId: args.groupId
}).first()
if (relExist) {
throw new gql.GraphQLError('User is already assigned to group.')
}
await grp.$relatedQuery('users').relate(usr.id) await grp.$relatedQuery('users').relate(usr.id)
return { return {
responseResult: graphHelper.generateSuccess('User has been assigned to group.') responseResult: graphHelper.generateSuccess('User has been assigned to group.')