Added group reject invite route and initial tests
This commit is contained in:
@@ -307,6 +307,53 @@ api.joinGroup = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @api {post} /groups/:groupId/reject Reject a group invitation
|
||||
* @apiVersion 3.0.0
|
||||
* @apiName RejectGroupInvite
|
||||
* @apiGroup Group
|
||||
*
|
||||
* @apiParam {UUID} groupId The group _id
|
||||
*
|
||||
* @apiSuccess {Object} group The group
|
||||
*/
|
||||
api.rejectGroupInvite = {
|
||||
method: 'POST',
|
||||
url: '/groups/:groupId/reject-invite',
|
||||
middlewares: [authWithHeaders(), cron],
|
||||
async handler (req, res) {
|
||||
let user = res.locals.user;
|
||||
|
||||
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty().isUUID();
|
||||
|
||||
let validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
let group = await Group.getGroup({user, groupId: req.params.groupId, optionalMembership: true}); // Do not fetch chat and work even if the user is not yet a member of the group
|
||||
if (!group) throw new NotFound(res.t('groupNotFound'));
|
||||
|
||||
let isUserInvited = false;
|
||||
|
||||
if (group.type === 'party' && group._id === user.invitations.party.id) {
|
||||
user.invitations.party = {};
|
||||
user.markModified('invitations.party');
|
||||
isUserInvited = true;
|
||||
} else if (group.type === 'guild') {
|
||||
let hasInvitation = removeFromArray(user.invitations.guilds, { id: group._id });
|
||||
|
||||
if (hasInvitation) {
|
||||
isUserInvited = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isUserInvited) throw new NotAuthorized(res.t('messageGroupRequiresInvite'));
|
||||
|
||||
await user.save();
|
||||
|
||||
res.respond(200, {});
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @api {post} /groups/:groupId/leave Leave a group
|
||||
* @apiVersion 3.0.0
|
||||
|
||||
Reference in New Issue
Block a user