mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
* move translatable string to apiMessages * use apiMessages instead of res.t for groupIdRequired / keepOrRemove * move pageMustBeNumber to apiMessages * change apimessages * move missingKeyParam to apiMessages * move more strings to apiMessages * fix lint * revert lodash imports to fix tests * fix webhook test * fix test * rollback key change of `keepOrRemove` * remove unneeded `req.language` param * extract more messages from i18n * add missing `missingTypeParam` message * Split api- and commonMessages * fix test * fix sanity * merge messages to an object, rename commonMessage to errorMessage * apiMessages -> apiError, commonMessages -> errorMessage, extract messages to separate objects * fix test * module.exports
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
import i18n from '../../i18n';
|
|
import content from '../../content/index';
|
|
import get from 'lodash/get';
|
|
import each from 'lodash/each';
|
|
import {
|
|
BadRequest,
|
|
NotAuthorized,
|
|
NotFound,
|
|
} from '../../libs/errors';
|
|
import errorMessage from '../../libs/errorMessage';
|
|
|
|
module.exports = function buyMysterySet (user, req = {}, analytics) {
|
|
let key = get(req, 'params.key');
|
|
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
|
|
|
if (!(user.purchased.plan.consecutive.trinkets > 0)) {
|
|
throw new NotAuthorized(i18n.t('notEnoughHourglasses', req.language));
|
|
}
|
|
|
|
let ref = content.timeTravelerStore(user);
|
|
let mysterySet = ref ? ref[key] : undefined;
|
|
|
|
if (!mysterySet) {
|
|
throw new NotFound(i18n.t('mysterySetNotFound', req.language));
|
|
}
|
|
|
|
each(mysterySet.items, item => {
|
|
user.items.gear.owned[item.key] = true;
|
|
if (analytics) {
|
|
analytics.track('acquire item', {
|
|
uuid: user._id,
|
|
itemKey: item.key,
|
|
itemType: 'Subscriber Gear',
|
|
acquireMethod: 'Hourglass',
|
|
category: 'behavior',
|
|
headers: req.headers,
|
|
});
|
|
}
|
|
});
|
|
|
|
user.purchased.plan.consecutive.trinkets--;
|
|
|
|
return [
|
|
{ items: user.items, purchasedPlanConsecutive: user.purchased.plan.consecutive },
|
|
i18n.t('hourglassPurchaseSet', req.language),
|
|
];
|
|
};
|