mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Merge branch 'sabrecat/quest-accept' into TheHollidayInn-api-v3-quests-abort
This commit is contained in:
@@ -76,5 +76,9 @@
|
|||||||
"questAlreadyUnderway": "Your party is already on a quest. Try again when the current quest has ended.",
|
"questAlreadyUnderway": "Your party is already on a quest. Try again when the current quest has ended.",
|
||||||
"questAlreadyAccepted": "You already accepted the quest invitation.",
|
"questAlreadyAccepted": "You already accepted the quest invitation.",
|
||||||
"noActiveQuestToAbort": "There is no active quest to abort.",
|
"noActiveQuestToAbort": "There is no active quest to abort.",
|
||||||
"onlyLeaderAbortQuest": "Only the group or quest leader can abort a quest."
|
"onlyLeaderAbortQuest": "Only the group or quest leader can abort a quest.",
|
||||||
|
"questAlreadyRejected": "You already rejected the quest invitation.",
|
||||||
|
"cantCancelActiveQuest": "You can not cancel an active quest, use the abort functionality.",
|
||||||
|
"onlyLeaderCancelQuest": "Only the group or quest leader can cancel the quest.",
|
||||||
|
"questInvitationDoesNotExist": "No quest invitation has been sent out yet."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,5 +78,6 @@
|
|||||||
"whichQuestStart": "Which quest do you want to start?",
|
"whichQuestStart": "Which quest do you want to start?",
|
||||||
"getMoreQuests": "Get more quests",
|
"getMoreQuests": "Get more quests",
|
||||||
"unlockedAQuest": "You unlocked a quest!",
|
"unlockedAQuest": "You unlocked a quest!",
|
||||||
"leveledUpReceivedQuest": "You leveled up to <strong>Level <%= level %></strong> and received a quest scroll!"
|
"leveledUpReceivedQuest": "You leveled up to <strong>Level <%= level %></strong> and received a quest scroll!",
|
||||||
|
"questInvitationDoesNotExist": "No quest invitation has been sent out yet."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ describe('POST /groups/:groupId/quests/leave', () => {
|
|||||||
expect(partyMembers[0].party.quest).to.eql(cleanUserQuestObj);
|
expect(partyMembers[0].party.quest).to.eql(cleanUserQuestObj);
|
||||||
expect(partyMembers[1].party.quest).to.eql(cleanUserQuestObj);
|
expect(partyMembers[1].party.quest).to.eql(cleanUserQuestObj);
|
||||||
expect(leader.items.quests[PET_QUEST]).to.equal(1);
|
expect(leader.items.quests[PET_QUEST]).to.equal(1);
|
||||||
expect(questingGroup.quest).to.deep.equal(abortResult);
|
expect(questingGroup.quest).to.deep.equal(res);
|
||||||
expect(questingGroup.quest).to.eql({
|
expect(questingGroup.quest).to.eql({
|
||||||
key: null,
|
key: null,
|
||||||
active: false,
|
active: false,
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
import {
|
||||||
|
createAndPopulateGroup,
|
||||||
|
translate as t,
|
||||||
|
generateUser,
|
||||||
|
} from '../../../../helpers/api-v3-integration.helper';
|
||||||
|
import { v4 as generateUUID } from 'uuid';
|
||||||
|
|
||||||
|
describe('POST /groups/:groupId/quests/cancel', () => {
|
||||||
|
let questingGroup;
|
||||||
|
let partyMembers;
|
||||||
|
let user;
|
||||||
|
let leader;
|
||||||
|
|
||||||
|
const PET_QUEST = 'whale';
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
let { group, groupLeader, members } = await createAndPopulateGroup({
|
||||||
|
groupDetails: { type: 'party', privacy: 'private' },
|
||||||
|
members: 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
questingGroup = group;
|
||||||
|
leader = groupLeader;
|
||||||
|
partyMembers = members;
|
||||||
|
|
||||||
|
await leader.update({
|
||||||
|
[`items.quests.${PET_QUEST}`]: 1,
|
||||||
|
});
|
||||||
|
user = await generateUser();
|
||||||
|
});
|
||||||
|
|
||||||
|
context('failure conditions', () => {
|
||||||
|
it('returns an error when group is not found', async () => {
|
||||||
|
await expect(partyMembers[0].post(`/groups/${generateUUID()}/quests/cancel`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 404,
|
||||||
|
error: 'NotFound',
|
||||||
|
message: t('groupNotFound'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not reject quest for a group in which user is not a member', async () => {
|
||||||
|
await expect(user.post(`/groups/${questingGroup._id}/quests/cancel`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 404,
|
||||||
|
error: 'NotFound',
|
||||||
|
message: t('groupNotFound'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns an error when group is a guild', async () => {
|
||||||
|
let { group: guild, groupLeader: guildLeader } = await createAndPopulateGroup({
|
||||||
|
groupDetails: { type: 'guild', privacy: 'private' },
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(guildLeader.post(`/groups/${guild._id}/quests/cancel`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
error: 'NotAuthorized',
|
||||||
|
message: t('guildQuestsNotSupported'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns an error when group is not on a quest', async () => {
|
||||||
|
await expect(partyMembers[0].post(`/groups/${questingGroup._id}/quests/cancel`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 404,
|
||||||
|
error: 'NotFound',
|
||||||
|
message: t('questInvitationDoesNotExist'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('only the leader can cancel the quest', async () => {
|
||||||
|
await leader.post(`/groups/${questingGroup._id}/quests/invite/${PET_QUEST}`);
|
||||||
|
|
||||||
|
await expect(partyMembers[0].post(`/groups/${questingGroup._id}/quests/cancel`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
error: 'NotAuthorized',
|
||||||
|
message: t('onlyLeaderCancelQuest'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not cancel a quest already underway', async () => {
|
||||||
|
await leader.post(`/groups/${questingGroup._id}/quests/invite/${PET_QUEST}`);
|
||||||
|
await partyMembers[0].post(`/groups/${questingGroup._id}/quests/accept`);
|
||||||
|
// quest will start after everyone has accepted
|
||||||
|
await partyMembers[1].post(`/groups/${questingGroup._id}/quests/accept`);
|
||||||
|
|
||||||
|
await expect(leader.post(`/groups/${questingGroup._id}/quests/cancel`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
error: 'NotAuthorized',
|
||||||
|
message: t('cantCancelActiveQuest'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('cancels a quest', async () => {
|
||||||
|
await leader.post(`/groups/${questingGroup._id}/quests/invite/${PET_QUEST}`);
|
||||||
|
await partyMembers[0].post(`/groups/${questingGroup._id}/quests/accept`);
|
||||||
|
|
||||||
|
let res = await leader.post(`/groups/${questingGroup._id}/quests/cancel`);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
leader.sync(),
|
||||||
|
partyMembers[0].sync(),
|
||||||
|
partyMembers[1].sync(),
|
||||||
|
questingGroup.sync(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let clean = {
|
||||||
|
key: null,
|
||||||
|
progress: {
|
||||||
|
up: 0,
|
||||||
|
down: 0,
|
||||||
|
collect: {},
|
||||||
|
},
|
||||||
|
completed: null,
|
||||||
|
RSVPNeeded: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(leader.party.quest).eql(clean);
|
||||||
|
expect(partyMembers[1].party.quest).eql(clean);
|
||||||
|
expect(partyMembers[0].party.quest).eql(clean);
|
||||||
|
|
||||||
|
expect(res).to.eql(questingGroup.quest);
|
||||||
|
expect(questingGroup.quest).to.eql({
|
||||||
|
key: null,
|
||||||
|
active: false,
|
||||||
|
leader: null,
|
||||||
|
progress: {
|
||||||
|
collect: {},
|
||||||
|
},
|
||||||
|
members: {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
import {
|
||||||
|
createAndPopulateGroup,
|
||||||
|
translate as t,
|
||||||
|
generateUser,
|
||||||
|
} from '../../../../helpers/api-v3-integration.helper';
|
||||||
|
import { v4 as generateUUID } from 'uuid';
|
||||||
|
|
||||||
|
describe('POST /groups/:groupId/quests/reject', () => {
|
||||||
|
let questingGroup;
|
||||||
|
let partyMembers;
|
||||||
|
let user;
|
||||||
|
let leader;
|
||||||
|
|
||||||
|
const PET_QUEST = 'whale';
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
let { group, groupLeader, members } = await createAndPopulateGroup({
|
||||||
|
groupDetails: { type: 'party', privacy: 'private' },
|
||||||
|
members: 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
questingGroup = group;
|
||||||
|
leader = groupLeader;
|
||||||
|
partyMembers = members;
|
||||||
|
|
||||||
|
await leader.update({
|
||||||
|
[`items.quests.${PET_QUEST}`]: 1,
|
||||||
|
});
|
||||||
|
user = await generateUser();
|
||||||
|
});
|
||||||
|
|
||||||
|
context('failure conditions', () => {
|
||||||
|
it('returns an error when group is not found', async () => {
|
||||||
|
await expect(partyMembers[0].post(`/groups/${generateUUID()}/quests/reject`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 404,
|
||||||
|
error: 'NotFound',
|
||||||
|
message: t('groupNotFound'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not accept quest for a group in which user is not a member', async () => {
|
||||||
|
await expect(user.post(`/groups/${questingGroup._id}/quests/accept`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 404,
|
||||||
|
error: 'NotFound',
|
||||||
|
message: t('groupNotFound'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns an error when group is a guild', async () => {
|
||||||
|
let { group: guild, groupLeader: guildLeader } = await createAndPopulateGroup({
|
||||||
|
groupDetails: { type: 'guild', privacy: 'private' },
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(guildLeader.post(`/groups/${guild._id}/quests/reject`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
error: 'NotAuthorized',
|
||||||
|
message: t('guildQuestsNotSupported'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns an error when group is not on a quest', async () => {
|
||||||
|
await expect(partyMembers[0].post(`/groups/${questingGroup._id}/quests/reject`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 404,
|
||||||
|
error: 'NotFound',
|
||||||
|
message: t('questInvitationDoesNotExist'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('return an error when an user rejects an invite twice', async () => {
|
||||||
|
await leader.post(`/groups/${questingGroup._id}/quests/invite/${PET_QUEST}`);
|
||||||
|
await partyMembers[0].post(`/groups/${questingGroup._id}/quests/reject`);
|
||||||
|
|
||||||
|
await expect(partyMembers[0].post(`/groups/${questingGroup._id}/quests/reject`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 400,
|
||||||
|
error: 'BadRequest',
|
||||||
|
message: t('questAlreadyRejected'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('return an error when an user rejects an invite already accepted', async () => {
|
||||||
|
await leader.post(`/groups/${questingGroup._id}/quests/invite/${PET_QUEST}`);
|
||||||
|
await partyMembers[0].post(`/groups/${questingGroup._id}/quests/accept`);
|
||||||
|
|
||||||
|
await expect(partyMembers[0].post(`/groups/${questingGroup._id}/quests/reject`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 400,
|
||||||
|
error: 'BadRequest',
|
||||||
|
message: t('questAlreadyAccepted'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not reject invite for a quest already underway', async () => {
|
||||||
|
await leader.post(`/groups/${questingGroup._id}/quests/invite/${PET_QUEST}`);
|
||||||
|
await partyMembers[0].post(`/groups/${questingGroup._id}/quests/accept`);
|
||||||
|
// quest will start after everyone has accepted
|
||||||
|
await partyMembers[1].post(`/groups/${questingGroup._id}/quests/accept`);
|
||||||
|
|
||||||
|
await expect(partyMembers[0].post(`/groups/${questingGroup._id}/quests/reject`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
error: 'NotAuthorized',
|
||||||
|
message: t('questAlreadyUnderway'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
context('successfully quest rejection', () => {
|
||||||
|
let cleanUserQuestObj = {
|
||||||
|
key: null,
|
||||||
|
progress: {
|
||||||
|
up: 0,
|
||||||
|
down: 0,
|
||||||
|
collect: {},
|
||||||
|
},
|
||||||
|
completed: null,
|
||||||
|
RSVPNeeded: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
it('rejects a quest invitation', async () => {
|
||||||
|
await leader.post(`/groups/${questingGroup._id}/quests/invite/${PET_QUEST}`);
|
||||||
|
|
||||||
|
let res = await partyMembers[0].post(`/groups/${questingGroup._id}/quests/reject`);
|
||||||
|
await partyMembers[0].sync();
|
||||||
|
await questingGroup.sync();
|
||||||
|
|
||||||
|
expect(partyMembers[0].party.quest).to.eql(cleanUserQuestObj);
|
||||||
|
expect(questingGroup.quest.members[partyMembers[0]._id]).to.be.false;
|
||||||
|
expect(questingGroup.quest.active).to.be.false;
|
||||||
|
expect(res).to.eql(questingGroup.quest);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('starts the quest when the last user reject', async () => {
|
||||||
|
await leader.post(`/groups/${questingGroup._id}/quests/invite/${PET_QUEST}`);
|
||||||
|
await partyMembers[0].post(`/groups/${questingGroup._id}/quests/accept`);
|
||||||
|
await partyMembers[1].post(`/groups/${questingGroup._id}/quests/reject`);
|
||||||
|
await questingGroup.sync();
|
||||||
|
|
||||||
|
expect(questingGroup.quest.active).to.be.true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -21,7 +21,7 @@ import { quests as questScrolls } from '../../../../common/script/content';
|
|||||||
function canStartQuestAutomatically (group) {
|
function canStartQuestAutomatically (group) {
|
||||||
// If all members are either true (accepted) or false (rejected) return true
|
// If all members are either true (accepted) or false (rejected) return true
|
||||||
// If any member is null/undefined (undecided) return false
|
// If any member is null/undefined (undecided) return false
|
||||||
return _.every(group.quest.members, Boolean);
|
return _.every(group.quest.members, _.isBoolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
let api = {};
|
let api = {};
|
||||||
@@ -180,6 +180,113 @@ api.acceptQuest = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {post} /groups/:groupId/quests/reject Reject a quest
|
||||||
|
* @apiVersion 3.0.0
|
||||||
|
* @apiName RejectQuest
|
||||||
|
* @apiGroup Group
|
||||||
|
*
|
||||||
|
* @apiParam {string} groupId The group _id (or 'party')
|
||||||
|
*
|
||||||
|
* @apiSuccess {Object} quest Quest Object
|
||||||
|
*/
|
||||||
|
api.rejectQuest = {
|
||||||
|
method: 'POST',
|
||||||
|
url: '/groups/:groupId/quests/reject',
|
||||||
|
middlewares: [authWithHeaders(), cron],
|
||||||
|
async handler (req, res) {
|
||||||
|
let user = res.locals.user;
|
||||||
|
|
||||||
|
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty();
|
||||||
|
|
||||||
|
let validationErrors = req.validationErrors();
|
||||||
|
if (validationErrors) throw validationErrors;
|
||||||
|
|
||||||
|
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'));
|
||||||
|
if (!group.quest.key) throw new NotFound(res.t('questInvitationDoesNotExist'));
|
||||||
|
if (group.quest.active) throw new NotAuthorized(res.t('questAlreadyUnderway'));
|
||||||
|
if (group.quest.members[user._id]) throw new BadRequest(res.t('questAlreadyAccepted'));
|
||||||
|
if (group.quest.members[user._id] === false) throw new BadRequest(res.t('questAlreadyRejected'));
|
||||||
|
|
||||||
|
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 Q.all([
|
||||||
|
group.save(),
|
||||||
|
user.save(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
res.respond(200, savedGroup.quest);
|
||||||
|
|
||||||
|
analytics.track('quest', {
|
||||||
|
category: 'behavior',
|
||||||
|
owner: false,
|
||||||
|
response: 'reject',
|
||||||
|
gaLabel: 'reject',
|
||||||
|
questName: group.quest.key,
|
||||||
|
uuid: user._id,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {post} /groups/:groupId/quests/cancel Cancels a quest
|
||||||
|
* @apiVersion 3.0.0
|
||||||
|
* @apiName CancelQuest
|
||||||
|
* @apiGroup Group
|
||||||
|
*
|
||||||
|
* @apiParam {string} groupId The group _id (or 'party')
|
||||||
|
*
|
||||||
|
* @apiSuccess {Object} quest Quest Object
|
||||||
|
*/
|
||||||
|
api.cancelQuest = {
|
||||||
|
method: 'POST',
|
||||||
|
url: '/groups/:groupId/quests/cancel',
|
||||||
|
middlewares: [authWithHeaders(), cron],
|
||||||
|
async handler (req, res) {
|
||||||
|
// Cancel a quest BEFORE it has begun (i.e., in the invitation stage)
|
||||||
|
// Quest scroll has not yet left quest owner's inventory so no need to return it.
|
||||||
|
// Do not wipe quest progress for members because they'll want it to be applied to the next quest that's started.
|
||||||
|
let user = res.locals.user;
|
||||||
|
let groupId = req.params.groupId;
|
||||||
|
|
||||||
|
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty();
|
||||||
|
|
||||||
|
let validationErrors = req.validationErrors();
|
||||||
|
if (validationErrors) throw validationErrors;
|
||||||
|
|
||||||
|
let group = await Group.getGroup({user, groupId, fields: 'type leader 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'));
|
||||||
|
|
||||||
|
group.quest = Group.cleanGroupQuest();
|
||||||
|
group.markModified('quest');
|
||||||
|
|
||||||
|
let [savedGroup] = await Promise.all([
|
||||||
|
group.save(),
|
||||||
|
User.update(
|
||||||
|
{'party._id': groupId},
|
||||||
|
{$set: {'party.quest': Group.cleanQuestProgress()}},
|
||||||
|
{multi: true}
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
|
res.respond(200, savedGroup.quest);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} /groups/:groupId/quests/abort Abort the current quest
|
* @api {post} /groups/:groupId/quests/abort Abort the current quest
|
||||||
* @apiVersion 3.0.0
|
* @apiVersion 3.0.0
|
||||||
@@ -211,14 +318,14 @@ api.abortQuest = {
|
|||||||
if (user._id !== group.leader && user._id !== group.quest.leader) throw new NotAuthorized(res.t('onlyLeaderAbortQuest'));
|
if (user._id !== group.leader && user._id !== group.quest.leader) throw new NotAuthorized(res.t('onlyLeaderAbortQuest'));
|
||||||
|
|
||||||
let memberUpdates = User.update({
|
let memberUpdates = User.update({
|
||||||
'party._id': groupId
|
'party._id': groupId,
|
||||||
}, {
|
}, {
|
||||||
$set: {'party.quest': Group.cleanQuestProgress()},
|
$set: {'party.quest': Group.cleanQuestProgress()},
|
||||||
$inc: {_v: 1}, // TODO update middleware
|
$inc: {_v: 1}, // TODO update middleware
|
||||||
}, {multi: true}).exec();
|
}, {multi: true}).exec();
|
||||||
|
|
||||||
let questLeaderUpdate = User.update({
|
let questLeaderUpdate = User.update({
|
||||||
_id: group.quest.leader
|
_id: group.quest.leader,
|
||||||
}, {
|
}, {
|
||||||
$inc: {
|
$inc: {
|
||||||
[`items.quests.${group.quest.key}`]: 1, // give back the quest to the quest leader
|
[`items.quests.${group.quest.key}`]: 1, // give back the quest to the quest leader
|
||||||
|
|||||||
@@ -300,8 +300,8 @@ schema.methods.startQuest = async function startQuest (user) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// return a clean object for user.quest
|
||||||
function _cleanQuestProgress (merge) {
|
function _cleanQuestProgress (merge) {
|
||||||
// TODO clone? (also in sendChat message)
|
|
||||||
let clean = {
|
let clean = {
|
||||||
key: null,
|
key: null,
|
||||||
progress: {
|
progress: {
|
||||||
@@ -321,8 +321,22 @@ function _cleanQuestProgress (merge) {
|
|||||||
return clean;
|
return clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO move to User.cleanQuestProgress?
|
||||||
schema.statics.cleanQuestProgress = _cleanQuestProgress;
|
schema.statics.cleanQuestProgress = _cleanQuestProgress;
|
||||||
|
|
||||||
|
// returns a clean object for group.quest
|
||||||
|
schema.statics.cleanGroupQuest = function cleanGroupQuest () {
|
||||||
|
return {
|
||||||
|
key: null,
|
||||||
|
active: false,
|
||||||
|
leader: null,
|
||||||
|
progress: {
|
||||||
|
collect: {},
|
||||||
|
},
|
||||||
|
members: {},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// Participants: Grant rewards & achievements, finish quest
|
// Participants: Grant rewards & achievements, finish quest
|
||||||
// Returns the promise from update().exec()
|
// Returns the promise from update().exec()
|
||||||
schema.methods.finishQuest = function finishQuest (quest) {
|
schema.methods.finishQuest = function finishQuest (quest) {
|
||||||
|
|||||||
Reference in New Issue
Block a user