mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Ported open mystery item, added unit tests, added route, and integration tests
This commit is contained in:
@@ -114,6 +114,7 @@ import feed from './ops/feed';
|
||||
import equip from './ops/equip';
|
||||
import changeClass from './ops/changeClass';
|
||||
import disableClasses from './ops/disableClasses';
|
||||
import openMysteryItem from './ops/openMysteryItem';
|
||||
|
||||
api.ops = {
|
||||
scoreTask,
|
||||
@@ -129,6 +130,7 @@ api.ops = {
|
||||
equip,
|
||||
changeClass,
|
||||
disableClasses,
|
||||
openMysteryItem,
|
||||
};
|
||||
|
||||
import handleTwoHanded from './fns/handleTwoHanded';
|
||||
|
||||
@@ -1,32 +1,40 @@
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import {
|
||||
BadRequest,
|
||||
} from '../libs/errors';
|
||||
import _ from 'lodash';
|
||||
|
||||
module.exports = function openMysteryItem (user, req = {}, analytics) {
|
||||
let item = user.purchased.plan.mysteryItems.shift();
|
||||
|
||||
module.exports = function(user, req, cb, analytics) {
|
||||
var analyticsData, item, ref, ref1;
|
||||
item = (ref = user.purchased.plan) != null ? (ref1 = ref.mysteryItems) != null ? ref1.shift() : void 0 : void 0;
|
||||
if (!item) {
|
||||
return typeof cb === "function" ? cb({
|
||||
code: 400,
|
||||
message: "Empty"
|
||||
}) : void 0;
|
||||
}
|
||||
item = content.gear.flat[item];
|
||||
user.items.gear.owned[item.key] = true;
|
||||
if (typeof user.markModified === "function") {
|
||||
user.markModified('purchased.plan.mysteryItems');
|
||||
throw new BadRequest(i18n.t('mysteryItemIsEmpty', req.language));
|
||||
}
|
||||
|
||||
item = _.cloneDeep(content.gear.flat[item]);
|
||||
item.notificationType = 'Mystery';
|
||||
analyticsData = {
|
||||
uuid: user._id,
|
||||
itemKey: item,
|
||||
itemType: 'Subscriber Gear',
|
||||
acquireMethod: 'Subscriber',
|
||||
category: 'behavior'
|
||||
};
|
||||
if (analytics != null) {
|
||||
analytics.track('open mystery item', analyticsData);
|
||||
user.items.gear.owned[item.key] = true;
|
||||
|
||||
user.markModified('purchased.plan.mysteryItems');
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('open mystery item', {
|
||||
uuid: user._id,
|
||||
itemKey: item,
|
||||
itemType: 'Subscriber Gear',
|
||||
acquireMethod: 'Subscriber',
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
(user._tmp != null ? user._tmp : user._tmp = {}).drop = item;
|
||||
if (!user._tmp) user._tmp = {};
|
||||
user._tmp.drop = item;
|
||||
}
|
||||
return typeof cb === "function" ? cb(null, user.items.gear.owned) : void 0;
|
||||
|
||||
return {
|
||||
message: i18n.t('mysteryItemOpened', req.language),
|
||||
data: user.items.gear.owned,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user