Clear invites from user when the request fails because the invite is invalid (#7852)

* making requests to accept or reject a request fail because the invite is invalid clear the invite from the user so it doesn't require admin intervention. part of #7653

* Adding await
This commit is contained in:
Travis
2016-08-05 10:34:06 -07:00
committed by Blade Barringer
parent 093c5a72df
commit d7c5d05f13
3 changed files with 39 additions and 12 deletions

View File

@@ -161,6 +161,9 @@ api.acceptQuest = {
let validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;
user.party.quest.RSVPNeeded = false;
await user.save();
let group = await Group.getGroup({user, groupId: req.params.groupId, fields: 'type quest'});
if (!group) throw new NotFound(res.t('groupNotFound'));
@@ -171,16 +174,12 @@ api.acceptQuest = {
group.markModified('quest');
group.quest.members[user._id] = true;
user.party.quest.RSVPNeeded = false;
if (canStartQuestAutomatically(group)) {
await group.startQuest(user);
}
let [savedGroup] = await Bluebird.all([
group.save(),
user.save(),
]);
let savedGroup = await group.save();
res.respond(200, savedGroup.quest);
@@ -218,6 +217,10 @@ api.rejectQuest = {
let validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;
user.party.quest = Group.cleanQuestProgress();
user.markModified('party.quest');
await user.save();
let group = await Group.getGroup({user, groupId: req.params.groupId, fields: 'type quest'});
if (!group) throw new NotFound(res.t('groupNotFound'));
if (group.type !== 'party') throw new NotAuthorized(res.t('guildQuestsNotSupported'));
@@ -229,17 +232,11 @@ api.rejectQuest = {
group.quest.members[user._id] = false;
group.markModified('quest.members');
user.party.quest = Group.cleanQuestProgress();
user.markModified('party.quest');
if (canStartQuestAutomatically(group)) {
await group.startQuest(user);
}
let [savedGroup] = await Bluebird.all([
group.save(),
user.save(),
]);
let savedGroup = await group.save();
res.respond(200, savedGroup.quest);