mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-27 05:29:59 +00:00
33 lines
1 KiB
JavaScript
33 lines
1 KiB
JavaScript
|
|
import content from '../content/index';
|
||
|
|
|
||
|
|
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');
|
||
|
|
}
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
if (typeof window !== 'undefined') {
|
||
|
|
(user._tmp !== null ? user._tmp : user._tmp = {}).drop = item;
|
||
|
|
}
|
||
|
|
return typeof cb === 'function' ? cb(null, user.items.gear.owned) : void 0;
|
||
|
|
};
|