feat(analytics): initial Habitica-owned solution
This commit is contained in:
committed by
Kalista Payne
parent
746fcfff49
commit
e6ffd69148
@@ -1,7 +1,6 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import forEach from 'lodash/forEach';
|
||||
import isFunction from 'lodash/isFunction';
|
||||
import pick from 'lodash/pick';
|
||||
import nconf from 'nconf';
|
||||
import get from 'lodash/get';
|
||||
import { authWithHeaders } from '../../middlewares/auth';
|
||||
@@ -27,7 +26,6 @@ import * as inboxLib from '../../libs/inbox';
|
||||
import * as userLib from '../../libs/user';
|
||||
import { model as UserHistory } from '../../models/userHistory';
|
||||
|
||||
const OFFICIAL_PLATFORMS = ['habitica-web', 'habitica-ios', 'habitica-android'];
|
||||
const TECH_ASSISTANCE_EMAIL = nconf.get('EMAILS_TECH_ASSISTANCE_EMAIL');
|
||||
const DELETE_CONFIRMATION = 'DELETE';
|
||||
|
||||
@@ -325,13 +323,6 @@ api.deleteUser = {
|
||||
]);
|
||||
}
|
||||
|
||||
res.analytics.track('account delete', {
|
||||
user: pick(user, ['preferences', 'registeredThrough']),
|
||||
uuid: user._id,
|
||||
hitType: 'event',
|
||||
category: 'behavior',
|
||||
});
|
||||
|
||||
res.respond(200, {});
|
||||
},
|
||||
};
|
||||
@@ -441,7 +432,7 @@ api.sleep = {
|
||||
url: '/user/sleep',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const sleepRes = common.ops.sleep(user, req, res.analytics);
|
||||
const sleepRes = common.ops.sleep(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...sleepRes);
|
||||
},
|
||||
@@ -500,10 +491,7 @@ api.buy = {
|
||||
let quantity = 1;
|
||||
if (req.body.quantity) quantity = req.body.quantity;
|
||||
req.quantity = quantity;
|
||||
if (OFFICIAL_PLATFORMS.indexOf(req.headers['x-client']) === -1) {
|
||||
res.analytics = undefined;
|
||||
}
|
||||
const buyRes = await common.ops.buy(user, req, res.analytics);
|
||||
const buyRes = await common.ops.buy(user, req);
|
||||
|
||||
await user.save();
|
||||
|
||||
@@ -558,7 +546,7 @@ api.buyGear = {
|
||||
url: '/user/buy-gear/:key',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const buyGearRes = await common.ops.buy(user, req, res.analytics);
|
||||
const buyGearRes = await common.ops.buy(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...buyGearRes);
|
||||
},
|
||||
@@ -600,10 +588,7 @@ api.buyArmoire = {
|
||||
const { user } = res.locals;
|
||||
req.type = 'armoire';
|
||||
req.params.key = 'armoire';
|
||||
if (OFFICIAL_PLATFORMS.indexOf(req.headers['x-client']) === -1) {
|
||||
res.analytics = undefined;
|
||||
}
|
||||
const buyArmoireResponse = await common.ops.buy(user, req, res.analytics);
|
||||
const buyArmoireResponse = await common.ops.buy(user, req);
|
||||
await user.save();
|
||||
await UserHistory.beginUserHistoryUpdate(user._id, req.headers)
|
||||
.withArmoire(buyArmoireResponse[0].armoire.dropKey || 'experience')
|
||||
@@ -646,7 +631,7 @@ api.buyHealthPotion = {
|
||||
const { user } = res.locals;
|
||||
req.type = 'potion';
|
||||
req.params.key = 'potion';
|
||||
const buyHealthPotionResponse = await common.ops.buy(user, req, res.analytics);
|
||||
const buyHealthPotionResponse = await common.ops.buy(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...buyHealthPotionResponse);
|
||||
},
|
||||
@@ -688,7 +673,7 @@ api.buyMysterySet = {
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
req.type = 'mystery';
|
||||
const buyMysterySetRes = await common.ops.buy(user, req, res.analytics);
|
||||
const buyMysterySetRes = await common.ops.buy(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...buyMysterySetRes);
|
||||
},
|
||||
@@ -731,7 +716,7 @@ api.buyQuest = {
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
req.type = 'quest';
|
||||
const buyQuestRes = await common.ops.buy(user, req, res.analytics);
|
||||
const buyQuestRes = await common.ops.buy(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...buyQuestRes);
|
||||
},
|
||||
@@ -818,7 +803,7 @@ api.hatch = {
|
||||
url: '/user/hatch/:egg/:hatchingPotion',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const hatchRes = common.ops.hatch(user, req, res.analytics);
|
||||
const hatchRes = common.ops.hatch(user, req);
|
||||
|
||||
await user.save();
|
||||
|
||||
@@ -916,7 +901,7 @@ api.feed = {
|
||||
url: '/user/feed/:pet/:food',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const feedRes = common.ops.feed(user, req, res.analytics);
|
||||
const feedRes = common.ops.feed(user, req);
|
||||
|
||||
await user.save();
|
||||
|
||||
@@ -964,7 +949,7 @@ api.changeClass = {
|
||||
url: '/user/change-class',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const changeClassRes = await common.ops.changeClass(user, req, res.analytics);
|
||||
const changeClassRes = await common.ops.changeClass(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...changeClassRes);
|
||||
},
|
||||
@@ -1040,7 +1025,7 @@ api.purchase = {
|
||||
if (req.body.quantity) quantity = req.body.quantity;
|
||||
req.quantity = quantity;
|
||||
|
||||
const purchaseRes = await common.ops.buy(user, req, res.analytics);
|
||||
const purchaseRes = await common.ops.buy(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...purchaseRes);
|
||||
},
|
||||
@@ -1083,7 +1068,6 @@ api.userPurchaseHourglass = {
|
||||
const purchaseHourglassRes = await common.ops.buy(
|
||||
user,
|
||||
req,
|
||||
res.analytics,
|
||||
{ quantity, hourglass: true },
|
||||
);
|
||||
await user.save();
|
||||
@@ -1180,7 +1164,7 @@ api.userOpenMysteryItem = {
|
||||
url: '/user/open-mystery-item',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const openMysteryItemRes = common.ops.openMysteryItem(user, req, res.analytics);
|
||||
const openMysteryItemRes = common.ops.openMysteryItem(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...openMysteryItemRes);
|
||||
},
|
||||
@@ -1212,7 +1196,7 @@ api.userReleasePets = {
|
||||
url: '/user/release-pets',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const releasePetsRes = await common.ops.releasePets(user, req, res.analytics);
|
||||
const releasePetsRes = await common.ops.releasePets(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...releasePetsRes);
|
||||
},
|
||||
@@ -1261,7 +1245,7 @@ api.userReleaseBoth = {
|
||||
url: '/user/release-both',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const releaseBothRes = common.ops.releaseBoth(user, req, res.analytics);
|
||||
const releaseBothRes = common.ops.releaseBoth(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...releaseBothRes);
|
||||
},
|
||||
@@ -1297,7 +1281,7 @@ api.userReleaseMounts = {
|
||||
url: '/user/release-mounts',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const releaseMountsRes = await common.ops.releaseMounts(user, req, res.analytics);
|
||||
const releaseMountsRes = await common.ops.releaseMounts(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...releaseMountsRes);
|
||||
},
|
||||
@@ -1373,7 +1357,7 @@ api.userUnlock = {
|
||||
url: '/user/unlock',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const unlockRes = await common.ops.unlock(user, req, res.analytics);
|
||||
const unlockRes = await common.ops.unlock(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...unlockRes);
|
||||
},
|
||||
@@ -1399,7 +1383,7 @@ api.userRevive = {
|
||||
url: '/user/revive',
|
||||
async handler (req, res) {
|
||||
const { user } = res.locals;
|
||||
const reviveRes = common.ops.revive(user, req, res.analytics);
|
||||
const reviveRes = common.ops.revive(user, req);
|
||||
await user.save();
|
||||
res.respond(200, ...reviveRes);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user