Added quest reject route and intial tests

This commit is contained in:
Keith Holliday
2016-02-01 19:33:35 -06:00
parent e3c7d2834e
commit d5148a7bf0
3 changed files with 197 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ import { removeFromArray } from '../../libs/api-v3/collectionManipulators';
import * as firebase from '../../libs/api-v3/firebase';
import { sendTxn as sendTxnEmail } from '../../libs/api-v3/email';
import { encrypt } from '../../libs/api-v3/encryption';
import { quests as questScrolls } from '../../../../common/script/content';
import { mockAnalyticsService } from '../../libs/api-v3/analyticsService';
let api = {};
@@ -616,4 +618,99 @@ api.inviteToGroup = {
},
};
<<<<<<< e3c7d2834e6e5fa024afb71032c21177ca4124a7
=======
/**
* @api {post} /groups/:groupId/quests/invite Invite users to a quest
* @apiVersion 3.0.0
* @apiName InviteToQuest
* @apiGroup Group
*
* @apiParam {string} groupId The group _id (or 'party')
*
* @apiSuccess {Object} Quest Object
*/
api.inviteToQuest = {
method: 'POST',
url: '/groups/:groupId/quests/invite/:questKey',
middlewares: [authWithHeaders(), cron],
async handler (req, res) {
let user = res.locals.user;
let questKey = req.params.questKey;
let quest = questScrolls[questKey];
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 (!quest) throw new NotFound(res.t('questNotFound', { key: questKey }));
if (!user.items.quests[questKey]) throw new NotAuthorized(res.t('questNotOwned'));
if (user.stats.lvl < quest.lvl) throw new NotAuthorized(res.t('questLevelTooHigh', { level: quest.lvl }));
if (group.quest.key) throw new NotAuthorized(res.t('questAlreadyUnderway'));
// TODO Logic for quest invite and send back quest object
res.respond(200, {});
},
};
/**
* @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')
* @apiParam {string} questKey The quest _id
*
* @apiSuccess {Object} Quest Object
*/
api.rejectQuest = {
method: 'POST',
url: '/groups/:groupId/quests/reject/:questKey',
middlewares: [authWithHeaders(), cron],
async handler (req, res) {
let user = res.locals.user;
let questKey = req.params.questKey;
let quest = questScrolls[questKey];
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 (!quest) throw new NotFound(res.t('questNotFound', { key: questKey }));
if (!user.items.quests[questKey]) throw new NotAuthorized(res.t('questNotOwned'));
if (!group.quest.key) throw new NotFound(res.t('questInvitationDoesNotExist'));
let analyticsData = {
category: 'behavior',
owner: false,
response: 'reject',
gaLabel: 'reject',
questName: group.quest.key,
uuid: user._id,
};
mockAnalyticsService.track('quest', analyticsData);
// @TODO: Are we tracking members this way?
// group.quest.members[user._id] = false;
user.party.quest.RSVPNeeded = false;
user.party.quest.key = null;
await user.save();
// questStart(req,res,next);
res.respond(200, {});
},
};
>>>>>>> Added quest reject route and intial tests
export default api;