Add message of cancelled quest in party chat (#11106)

* Add message of cancelled quest in party chat

Issue #11093

* Delete trailing spaces

For successful passing the test

* Add test of cancelled quest's message

Also, added an explanation that partyMembers[1] hasn't accepted the invitation in the 'cancels a quest' test

* Fix: import Group

Import Group to pass Lint syntax test

* Move save function to Promise.all

* Fix moving save to Promise.all
This commit is contained in:
HydeHunter2
2019-04-14 18:55:20 +03:00
committed by Matteo Pagliazzi
parent 0bfd709116
commit 7a5a856ac6
2 changed files with 15 additions and 1 deletions

View File

@@ -363,17 +363,22 @@ api.cancelQuest = {
if (validationErrors) throw validationErrors;
let group = await Group.getGroup({user, groupId, fields: basicGroupFields.concat(' quest')});
if (!group) throw new NotFound(res.t('groupNotFound'));
if (group.type !== 'party') throw new NotAuthorized(res.t('guildQuestsNotSupported'));
if (!group.quest.key) throw new NotFound(res.t('questInvitationDoesNotExist'));
if (user._id !== group.leader && group.quest.leader !== user._id) throw new NotAuthorized(res.t('onlyLeaderCancelQuest'));
if (group.quest.active) throw new NotAuthorized(res.t('cantCancelActiveQuest'));
let questName = questScrolls[group.quest.key].text('en');
const newChatMessage = group.sendChat(`\`${user.profile.name} cancelled the party quest ${questName}.\``);
group.quest = Group.cleanGroupQuest();
group.markModified('quest');
let [savedGroup] = await Promise.all([
group.save(),
newChatMessage.save(),
User.update(
{'party._id': groupId},
Group.cleanQuestParty(),
@@ -405,7 +410,7 @@ api.abortQuest = {
url: '/groups/:groupId/quests/abort',
middlewares: [authWithHeaders()],
async handler (req, res) {
// Abort a quest AFTER it has begun (see questCancel for BEFORE)
// Abort a quest AFTER it has begun
let user = res.locals.user;
let groupId = req.params.groupId;