diff --git a/test/api/v3/unit/libs/analyticsService.test.js b/test/api/v3/unit/libs/analyticsService.test.js index ffba0c8144..4a547ac85a 100644 --- a/test/api/v3/unit/libs/analyticsService.test.js +++ b/test/api/v3/unit/libs/analyticsService.test.js @@ -11,6 +11,10 @@ describe('analyticsService', () => { sandbox.stub(Visitor.prototype, 'transaction'); }); + afterEach(() => { + sandbox.restore(); + }); + describe('#track', () => { let eventType, data; diff --git a/test/api/v3/unit/libs/email.test.js b/test/api/v3/unit/libs/email.test.js index 46476aa7ef..918c976bd5 100644 --- a/test/api/v3/unit/libs/email.test.js +++ b/test/api/v3/unit/libs/email.test.js @@ -53,31 +53,32 @@ describe('emails', () => { let pathToEmailLib = '../../../../../website/server/libs/email'; describe('sendEmail', () => { - it('can send an email using the default transport', () => { - let sendMailSpy = sandbox.stub().returns(defer().promise); + let sendMailSpy; + beforeEach(() => { + sendMailSpy = sandbox.stub().returns(defer().promise); sandbox.stub(nodemailer, 'createTransport').returns({ sendMail: sendMailSpy, }); + }); + afterEach(() => { + sandbox.restore(); + }); + + it('can send an email using the default transport', () => { let attachEmail = requireAgain(pathToEmailLib); attachEmail.send(); expect(sendMailSpy).to.be.calledOnce; }); it('logs errors', (done) => { - let deferred = defer(); - let sendMailSpy = sandbox.stub().returns(deferred.promise); - - sandbox.stub(nodemailer, 'createTransport').returns({ - sendMail: sendMailSpy, - }); sandbox.stub(logger, 'error'); let attachEmail = requireAgain(pathToEmailLib); attachEmail.send(); expect(sendMailSpy).to.be.calledOnce; - deferred.reject(); + defer().reject(); // wait for unhandledRejection event to fire setTimeout(() => { diff --git a/website/client-old/js/controllers/userCtrl.js b/website/client-old/js/controllers/userCtrl.js index b62207b945..0d8ca10dac 100644 --- a/website/client-old/js/controllers/userCtrl.js +++ b/website/client-old/js/controllers/userCtrl.js @@ -65,7 +65,7 @@ habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$ if (fullSet) { if (confirm(window.env.t('purchaseFor',{cost:cost*4})) !== true) return; if (User.user.balance < cost) return $rootScope.openModal('buyGems'); - } else if (!User.user.fns.dotGet('purchased.' + path)) { + } else if (!_.get(user, 'purchased.' + path)) { if (confirm(window.env.t('purchaseFor',{cost:cost*4})) !== true) return; if (User.user.balance < cost) return $rootScope.openModal('buyGems'); } diff --git a/website/common/script/fns/dotGet.js b/website/common/script/fns/dotGet.js deleted file mode 100644 index 3b45e54c71..0000000000 --- a/website/common/script/fns/dotGet.js +++ /dev/null @@ -1,7 +0,0 @@ -import _ from 'lodash'; - -// TODO remove completely, use _.get, only used in client - -module.exports = function dotGet (user, path) { - return _.get(user, path); -}; diff --git a/website/common/script/fns/dotSet.js b/website/common/script/fns/dotSet.js deleted file mode 100644 index ceb21605af..0000000000 --- a/website/common/script/fns/dotSet.js +++ /dev/null @@ -1,14 +0,0 @@ -import _ from 'lodash'; - -/* - This allows you to set object properties by dot-path. Eg, you can run pathSet('stats.hp',50,user) which is the same as - user.stats.hp = 50. This is useful because in our habitrpg-shared functions we're returning changesets as {path:value}, - so that different consumers can implement setters their own way. Derby needs model.set(path, value) for example, where - Angular sets object properties directly - in which case, this function will be used. -*/ - -// TODO use directly _.set and remove this fn, only used in client - -module.exports = function dotSet (user, path, val) { - return _.set(user, path, val); -}; diff --git a/website/common/script/fns/index.js b/website/common/script/fns/index.js index 04fddb2d75..e83cb0b6a1 100644 --- a/website/common/script/fns/index.js +++ b/website/common/script/fns/index.js @@ -2,24 +2,18 @@ import handleTwoHanded from './handleTwoHanded'; import predictableRandom from './predictableRandom'; import crit from './crit'; import randomVal from './randomVal'; -import dotSet from './dotSet'; -import dotGet from './dotGet'; import randomDrop from './randomDrop'; import autoAllocate from './autoAllocate'; import updateStats from './updateStats'; import ultimateGear from './ultimateGear'; -import nullify from './nullify'; module.exports = { handleTwoHanded, predictableRandom, crit, randomVal, - dotSet, - dotGet, randomDrop, autoAllocate, updateStats, ultimateGear, - nullify, }; diff --git a/website/common/script/fns/nullify.js b/website/common/script/fns/nullify.js deleted file mode 100644 index 38753071fc..0000000000 --- a/website/common/script/fns/nullify.js +++ /dev/null @@ -1,7 +0,0 @@ -// TODO remove once v2 is retired - -module.exports = function nullify (user) { - user.ops = null; - user.fns = null; - user = null; -}; diff --git a/website/common/script/index.js b/website/common/script/index.js index 8f32dcb456..5f8e745b22 100644 --- a/website/common/script/index.js +++ b/website/common/script/index.js @@ -43,12 +43,6 @@ api.diminishingReturns = statHelpers.diminishingReturns; import splitWhitespace from './libs/splitWhitespace'; api.$w = splitWhitespace; -import dotSet from './libs/dotSet'; -api.dotSet = dotSet; - -import dotGet from './libs/dotGet'; -api.dotGet = dotGet; - import refPush from './libs/refPush'; api.refPush = refPush; @@ -253,7 +247,6 @@ api.wrap = function wrapUser (user, main = true) { if (main) { user.ops = { - update: _.partial(importedOps.update, user), sleep: _.partial(importedOps.sleep, user), revive: _.partial(importedOps.revive, user), reset: _.partial(importedOps.reset, user), @@ -266,8 +259,6 @@ api.wrap = function wrapUser (user, main = true) { addTask: _.partial(importedOps.addTask, user), addTag: _.partial(importedOps.addTag, user), sortTag: _.partial(importedOps.sortTag, user), - getTags: _.partial(importedOps.getTags, user), - getTag: _.partial(importedOps.getTag, user), updateTag: _.partial(importedOps.updateTag, user), deleteTag: _.partial(importedOps.deleteTag, user), addWebhook: _.partial(importedOps.addWebhook, user), @@ -308,14 +299,11 @@ api.wrap = function wrapUser (user, main = true) { predictableRandom: _.partial(importedFns.predictableRandom, user), crit: _.partial(importedFns.crit, user), randomVal: _.partial(importedFns.randomVal, user), - dotSet: _.partial(importedFns.dotSet, user), - dotGet: _.partial(importedFns.dotGet, user), randomDrop: _.partial(importedFns.randomDrop, user), autoAllocate: _.partial(importedFns.autoAllocate, user), updateStats: _.partial(importedFns.updateStats, user), statsComputed: _.partial(statsComputed, user), ultimateGear: _.partial(importedFns.ultimateGear, user), - nullify: _.partial(importedFns.nullify, user), }; Object.defineProperty(user, '_statsComputed', { diff --git a/website/common/script/ops/addWebhook.js b/website/common/script/ops/addWebhook.js index c308d1b9e5..aefdee65fd 100644 --- a/website/common/script/ops/addWebhook.js +++ b/website/common/script/ops/addWebhook.js @@ -14,14 +14,10 @@ module.exports = function addWebhook (user, req = {}) { user.markModified('preferences.webhooks'); - if (req.v2 === true) { - return user.preferences.webhooks; - } else { - return [ - refPush(wh, { - url: req.body.url, - enabled: req.body.enabled, - }), - ]; - } + return [ + refPush(wh, { + url: req.body.url, + enabled: req.body.enabled, + }), + ]; }; diff --git a/website/common/script/ops/allocateNow.js b/website/common/script/ops/allocateNow.js index e8ae5d249c..a4d3f7cde4 100644 --- a/website/common/script/ops/allocateNow.js +++ b/website/common/script/ops/allocateNow.js @@ -1,15 +1,11 @@ import _ from 'lodash'; import autoAllocate from '../fns/autoAllocate'; -module.exports = function allocateNow (user, req = {}) { +module.exports = function allocateNow (user) { _.times(user.stats.points, () => autoAllocate(user)); user.stats.points = 0; - if (req.v2 === true) { - return _.pick(user, 'stats'); - } else { - return [ - user.stats, - ]; - } + return [ + user.stats, + ]; }; diff --git a/website/common/script/ops/buyArmoire.js b/website/common/script/ops/buyArmoire.js index 5dd76b4974..a07f7e8d79 100644 --- a/website/common/script/ops/buyArmoire.js +++ b/website/common/script/ops/buyArmoire.js @@ -105,12 +105,8 @@ module.exports = function buyArmoire (user, req = {}, analytics) { let resData = _.pick(user, splitWhitespace('items flags')); if (armoireResp) resData.armoire = armoireResp; - if (req.v2 === true) { - return resData; - } else { - return [ - resData, - message, - ]; - } + return [ + resData, + message, + ]; }; diff --git a/website/common/script/ops/buyGear.js b/website/common/script/ops/buyGear.js index 197c9932f5..3c275e74b2 100644 --- a/website/common/script/ops/buyGear.js +++ b/website/common/script/ops/buyGear.js @@ -60,12 +60,8 @@ module.exports = function buyGear (user, req = {}, analytics) { }); } - if (req.v2 === true) { - return _.pick(user, splitWhitespace('items achievements stats flags')); - } else { - return [ - _.pick(user, splitWhitespace('items achievements stats flags')), - message, - ]; - } + return [ + _.pick(user, splitWhitespace('items achievements stats flags')), + message, + ]; }; diff --git a/website/common/script/ops/buyHealthPotion.js b/website/common/script/ops/buyHealthPotion.js index b7a2e21db7..c2705d91bf 100644 --- a/website/common/script/ops/buyHealthPotion.js +++ b/website/common/script/ops/buyHealthPotion.js @@ -42,12 +42,8 @@ module.exports = function buyHealthPotion (user, req = {}, analytics) { }); } - if (req.v2 === true) { - return user.stats; - } else { - return [ - user.stats, - message, - ]; - } + return [ + user.stats, + message, + ]; }; diff --git a/website/common/script/ops/buyMysterySet.js b/website/common/script/ops/buyMysterySet.js index b0ade9926a..0cb10aac92 100644 --- a/website/common/script/ops/buyMysterySet.js +++ b/website/common/script/ops/buyMysterySet.js @@ -1,8 +1,6 @@ import i18n from '../i18n'; import content from '../content/index'; import _ from 'lodash'; -import splitWhitespace from '../libs/splitWhitespace'; -import pickDeep from '../libs/pickDeep'; import { BadRequest, NotAuthorized, @@ -45,12 +43,8 @@ module.exports = function buyMysterySet (user, req = {}, analytics) { user.purchased.plan.consecutive.trinkets--; - if (req.v2 === true) { - return pickDeep(user, splitWhitespace('items purchased.plan.consecutive')); - } else { - return [ - { items: user.items, purchasedPlanConsecutive: user.purchased.plan.consecutive }, - i18n.t('hourglassPurchaseSet', req.language), - ]; - } + return [ + { items: user.items, purchasedPlanConsecutive: user.purchased.plan.consecutive }, + i18n.t('hourglassPurchaseSet', req.language), + ]; }; diff --git a/website/common/script/ops/buyQuest.js b/website/common/script/ops/buyQuest.js index bd03abfe0f..5fa62b28aa 100644 --- a/website/common/script/ops/buyQuest.js +++ b/website/common/script/ops/buyQuest.js @@ -38,14 +38,10 @@ module.exports = function buyQuest (user, req = {}, analytics) { }); } - if (req.v2 === true) { - return user.items.quests; - } else { - return [ - user.items.quests, - i18n.t('messageBought', { - itemText: item.text(req.language), - }, req.language), - ]; - } + return [ + user.items.quests, + i18n.t('messageBought', { + itemText: item.text(req.language), + }, req.language), + ]; }; diff --git a/website/common/script/ops/buySpecialSpell.js b/website/common/script/ops/buySpecialSpell.js index 20ea0251aa..6ad6eb08f4 100644 --- a/website/common/script/ops/buySpecialSpell.js +++ b/website/common/script/ops/buySpecialSpell.js @@ -22,14 +22,10 @@ module.exports = function buySpecialSpell (user, req = {}) { user.items.special[key]++; - if (req.v2 === true) { - return _.pick(user, splitWhitespace('items stats')); - } else { - return [ - _.pick(user, splitWhitespace('items stats')), - i18n.t('messageBought', { - itemText: item.text(req.language), - }, req.language), - ]; - } + return [ + _.pick(user, splitWhitespace('items stats')), + i18n.t('messageBought', { + itemText: item.text(req.language), + }, req.language), + ]; }; diff --git a/website/common/script/ops/changeClass.js b/website/common/script/ops/changeClass.js index 67615958ba..f983145f07 100644 --- a/website/common/script/ops/changeClass.js +++ b/website/common/script/ops/changeClass.js @@ -69,11 +69,7 @@ module.exports = function changeClass (user, req = {}, analytics) { user.flags.classSelected = false; } - if (req.v2 === true) { - return _.pick(user, splitWhitespace('stats flags items preferences')); - } else { - return [ - _.pick(user, splitWhitespace('stats flags items preferences')), - ]; - } + return [ + _.pick(user, splitWhitespace('stats flags items preferences')), + ]; }; diff --git a/website/common/script/ops/disableClasses.js b/website/common/script/ops/disableClasses.js index e611bb0872..182ca956e7 100644 --- a/website/common/script/ops/disableClasses.js +++ b/website/common/script/ops/disableClasses.js @@ -2,7 +2,7 @@ import splitWhitespace from '../libs/splitWhitespace'; import { capByLevel } from '../statHelpers'; import _ from 'lodash'; -module.exports = function disableClasses (user, req = {}) { +module.exports = function disableClasses (user) { user.stats.class = 'warrior'; user.flags.classSelected = true; user.preferences.disableClasses = true; @@ -10,11 +10,7 @@ module.exports = function disableClasses (user, req = {}) { user.stats.str = capByLevel(user.stats.lvl); user.stats.points = 0; - if (req.v2 === true) { - return _.pick(user, splitWhitespace('stats flags preferences')); - } else { - return [ - _.pick(user, splitWhitespace('stats flags preferences')), - ]; - } + return [ + _.pick(user, splitWhitespace('stats flags preferences')), + ]; }; diff --git a/website/common/script/ops/equip.js b/website/common/script/ops/equip.js index 9c614915a7..4338f075eb 100644 --- a/website/common/script/ops/equip.js +++ b/website/common/script/ops/equip.js @@ -58,11 +58,7 @@ module.exports = function equip (user, req = {}) { } } - if (req.v2 === true) { - return user.items; - } else { - let res = [user.items]; - if (message) res.push(message); - return res; - } + let res = [user.items]; + if (message) res.push(message); + return res; }; diff --git a/website/common/script/ops/feed.js b/website/common/script/ops/feed.js index 8411bf6d65..e8e8acbb9e 100644 --- a/website/common/script/ops/feed.js +++ b/website/common/script/ops/feed.js @@ -80,14 +80,8 @@ module.exports = function feed (user, req = {}) { user.items.food[food.key]--; - if (req.v2 === true) { - return { - value: userPets[pet.key], - }; - } else { - return [ - userPets[pet.key], - message, - ]; - } + return [ + userPets[pet.key], + message, + ]; }; diff --git a/website/common/script/ops/getTag.js b/website/common/script/ops/getTag.js deleted file mode 100644 index 4a7db63128..0000000000 --- a/website/common/script/ops/getTag.js +++ /dev/null @@ -1,18 +0,0 @@ -import _ from 'lodash'; -import i18n from '../i18n'; -import { NotFound } from '../libs/errors'; - -// TODO used only in client, move there? - -module.exports = function getTag (user, req = {}) { - let tid = _.get(req, 'params.id'); - - let index = _.findIndex(user.tags, { - id: tid, - }); - if (index === -1) { - throw new NotFound(i18n.t('messageTagNotFound', req.language)); - } - - return user.tags[index]; -}; diff --git a/website/common/script/ops/getTags.js b/website/common/script/ops/getTags.js deleted file mode 100644 index a96589a831..0000000000 --- a/website/common/script/ops/getTags.js +++ /dev/null @@ -1,5 +0,0 @@ -// TODO used only in client, move there? - -module.exports = function getTags (user) { - return user.tags; -}; diff --git a/website/common/script/ops/hatch.js b/website/common/script/ops/hatch.js index 87adbf3276..ac70296ced 100644 --- a/website/common/script/ops/hatch.js +++ b/website/common/script/ops/hatch.js @@ -33,12 +33,8 @@ module.exports = function hatch (user, req = {}) { user.items.eggs[egg]--; user.items.hatchingPotions[hatchingPotion]--; - if (req.v2 === true) { - return user.items; - } else { - return [ - user.items, - i18n.t('messageHatched', req.language), - ]; - } + return [ + user.items, + i18n.t('messageHatched', req.language), + ]; }; diff --git a/website/common/script/ops/hourglassPurchase.js b/website/common/script/ops/hourglassPurchase.js index 8367df776a..5134b3f8a4 100644 --- a/website/common/script/ops/hourglassPurchase.js +++ b/website/common/script/ops/hourglassPurchase.js @@ -5,7 +5,6 @@ import { BadRequest, NotAuthorized, } from '../libs/errors'; -import splitWhitespace from '../libs/splitWhitespace'; module.exports = function purchaseHourglass (user, req = {}, analytics) { let key = _.get(req, 'params.key'); @@ -51,12 +50,8 @@ module.exports = function purchaseHourglass (user, req = {}, analytics) { }); } - if (req.v2 === true) { - return _.pick(user, splitWhitespace('items purchased.plan.consecutive')); - } else { - return [ - { items: user.items, purchasedPlanConsecutive: user.purchased.plan.consecutive }, - i18n.t('hourglassPurchase', req.language), - ]; - } + return [ + { items: user.items, purchasedPlanConsecutive: user.purchased.plan.consecutive }, + i18n.t('hourglassPurchase', req.language), + ]; }; diff --git a/website/common/script/ops/index.js b/website/common/script/ops/index.js index 606a3599c9..5ce917ae0a 100644 --- a/website/common/script/ops/index.js +++ b/website/common/script/ops/index.js @@ -1,4 +1,3 @@ -import update from './update'; import sleep from './sleep'; import revive from './revive'; import reset from './reset'; @@ -11,8 +10,6 @@ import deleteTask from './deleteTask'; import addTask from './addTask'; import addTag from './addTag'; import sortTag from './sortTag'; -import getTags from './getTags'; -import getTag from './getTag'; import updateTag from './updateTag'; import deleteTag from './deleteTag'; import addWebhook from './addWebhook'; @@ -47,7 +44,6 @@ import scoreTask from './scoreTask'; import markPmsRead from './markPMSRead'; module.exports = { - update, sleep, revive, reset, @@ -60,8 +56,6 @@ module.exports = { addTask, addTag, sortTag, - getTags, - getTag, updateTag, deleteTag, addWebhook, diff --git a/website/common/script/ops/markPMSRead.js b/website/common/script/ops/markPMSRead.js index add9f49de5..ad9beab9b5 100644 --- a/website/common/script/ops/markPMSRead.js +++ b/website/common/script/ops/markPMSRead.js @@ -1,14 +1,10 @@ import i18n from '../i18n'; -module.exports = function markPmsRead (user, req = {}) { +module.exports = function markPmsRead (user) { user.inbox.newMessages = 0; - if (req.v2 === true) { - return user; - } else { - return [ - user.inbox.newMessages, - i18n.t('pmsMarkedRead'), - ]; - } + return [ + user.inbox.newMessages, + i18n.t('pmsMarkedRead'), + ]; }; diff --git a/website/common/script/ops/openMysteryItem.js b/website/common/script/ops/openMysteryItem.js index 9f6765ecfe..af3c2ba9ce 100644 --- a/website/common/script/ops/openMysteryItem.js +++ b/website/common/script/ops/openMysteryItem.js @@ -28,12 +28,8 @@ module.exports = function openMysteryItem (user, req = {}, analytics) { }); } - if (req.v2 === true) { - return user.items.gear.owned; - } else { - return [ - item, - i18n.t('mysteryItemOpened', req.language), - ]; - } + return [ + item, + i18n.t('mysteryItemOpened', req.language), + ]; }; diff --git a/website/common/script/ops/purchase.js b/website/common/script/ops/purchase.js index fac9ee5e0e..02cae962bb 100644 --- a/website/common/script/ops/purchase.js +++ b/website/common/script/ops/purchase.js @@ -119,11 +119,7 @@ module.exports = function purchase (user, req = {}, analytics) { }); } - if (req.v2 === true) { - return _.pick(user, splitWhitespace('items balance')); - } else { - return [ - _.pick(user, splitWhitespace('items balance')), - ]; - } + return [ + _.pick(user, splitWhitespace('items balance')), + ]; }; diff --git a/website/common/script/ops/readCard.js b/website/common/script/ops/readCard.js index 57b0da4b00..84f65453a6 100644 --- a/website/common/script/ops/readCard.js +++ b/website/common/script/ops/readCard.js @@ -1,4 +1,3 @@ -import splitWhitespace from '../libs/splitWhitespace'; import _ from 'lodash'; import i18n from '../i18n'; import { @@ -21,12 +20,8 @@ module.exports = function readCard (user, req = {}) { user.items.special[`${cardType}Received`].shift(); user.flags.cardReceived = false; - if (req.v2 === true) { - return _.pick(user, splitWhitespace('items.special flags.cardReceived')); - } else { - return [ - { specialItems: user.items.special, cardReceived: user.flags.cardReceived }, - i18n.t('readCard', {cardType}, req.language), - ]; - } + return [ + { specialItems: user.items.special, cardReceived: user.flags.cardReceived }, + i18n.t('readCard', {cardType}, req.language), + ]; }; diff --git a/website/common/script/ops/rebirth.js b/website/common/script/ops/rebirth.js index 265e520491..d4a2b664b1 100644 --- a/website/common/script/ops/rebirth.js +++ b/website/common/script/ops/rebirth.js @@ -97,12 +97,8 @@ module.exports = function rebirth (user, tasks = [], req = {}, analytics) { user.stats.buffs = {}; - if (req.v2 === true) { - return user; - } else { - return [ - {user, tasks}, - i18n.t('rebirthComplete'), - ]; - } + return [ + {user, tasks}, + i18n.t('rebirthComplete'), + ]; }; diff --git a/website/common/script/ops/releaseBoth.js b/website/common/script/ops/releaseBoth.js index 7acec6b579..0ee46a5e71 100644 --- a/website/common/script/ops/releaseBoth.js +++ b/website/common/script/ops/releaseBoth.js @@ -58,12 +58,8 @@ module.exports = function releaseBoth (user, req = {}, analytics) { user.achievements.triadBingoCount++; } - if (req.v2 === true) { - return user; - } else { - return [ - _.pick(user, splitWhitespace('achievements items balance')), - i18n.t('mountsAndPetsReleased'), - ]; - } + return [ + _.pick(user, splitWhitespace('achievements items balance')), + i18n.t('mountsAndPetsReleased'), + ]; }; diff --git a/website/common/script/ops/releaseMounts.js b/website/common/script/ops/releaseMounts.js index bc2406f422..ac50a5a7af 100644 --- a/website/common/script/ops/releaseMounts.js +++ b/website/common/script/ops/releaseMounts.js @@ -33,12 +33,8 @@ module.exports = function releaseMounts (user, req = {}, analytics) { }); } - if (req.v2 === true) { - return user; - } else { - return [ - user.items.mounts, - i18n.t('mountsReleased'), - ]; - } + return [ + user.items.mounts, + i18n.t('mountsReleased'), + ]; }; diff --git a/website/common/script/ops/releasePets.js b/website/common/script/ops/releasePets.js index 499876925d..b637a5d3ba 100644 --- a/website/common/script/ops/releasePets.js +++ b/website/common/script/ops/releasePets.js @@ -31,12 +31,8 @@ module.exports = function releasePets (user, req = {}, analytics) { }); } - if (req.v2 === true) { - return user; - } else { - return [ - user.items.pets, - i18n.t('petsReleased'), - ]; - } + return [ + user.items.pets, + i18n.t('petsReleased'), + ]; }; diff --git a/website/common/script/ops/reroll.js b/website/common/script/ops/reroll.js index aabcce7e55..13edc69be0 100644 --- a/website/common/script/ops/reroll.js +++ b/website/common/script/ops/reroll.js @@ -30,12 +30,8 @@ module.exports = function reroll (user, tasks = [], req = {}, analytics) { }); } - if (req.v2 === true) { - return user; - } else { - return [ - {user, tasks}, - i18n.t('fortifyComplete'), - ]; - } + return [ + {user, tasks}, + i18n.t('fortifyComplete'), + ]; }; diff --git a/website/common/script/ops/reset.js b/website/common/script/ops/reset.js index f788356242..a973a019c7 100644 --- a/website/common/script/ops/reset.js +++ b/website/common/script/ops/reset.js @@ -1,7 +1,7 @@ import resetGear from '../fns/resetGear'; import i18n from '../i18n'; -module.exports = function reset (user, tasks = [], req = {}) { +module.exports = function reset (user, tasks = []) { user.stats.hp = 50; user.stats.lvl = 1; user.stats.gp = 0; @@ -20,12 +20,8 @@ module.exports = function reset (user, tasks = [], req = {}) { user.preferences.automaticAllocation = false; - if (req.v2 === true) { - return user; - } else { - return [ - {user, tasksToRemove}, - i18n.t('resetComplete'), - ]; - } + return [ + {user, tasksToRemove}, + i18n.t('resetComplete'), + ]; }; diff --git a/website/common/script/ops/revive.js b/website/common/script/ops/revive.js index 3112cee510..410594317e 100644 --- a/website/common/script/ops/revive.js +++ b/website/common/script/ops/revive.js @@ -97,12 +97,8 @@ module.exports = function revive (user, req = {}, analytics) { }); } - if (req.v2 === true) { - return user; - } else { - return [ - user.items, - message, - ]; - } + return [ + user.items, + message, + ]; }; diff --git a/website/common/script/ops/sell.js b/website/common/script/ops/sell.js index 10412da222..5da6c75ddc 100644 --- a/website/common/script/ops/sell.js +++ b/website/common/script/ops/sell.js @@ -33,11 +33,7 @@ module.exports = function sell (user, req = {}) { user.items[type][key]--; user.stats.gp += content[type][key].value; - if (req.v2 === true) { - return _.pick(user, splitWhitespace('stats items')); - } else { - return [ - _.pick(user, splitWhitespace('stats items')), - ]; - } + return [ + _.pick(user, splitWhitespace('stats items')), + ]; }; diff --git a/website/common/script/ops/sleep.js b/website/common/script/ops/sleep.js index 1a531ecb88..c84994c294 100644 --- a/website/common/script/ops/sleep.js +++ b/website/common/script/ops/sleep.js @@ -1,9 +1,5 @@ -module.exports = function sleep (user, req = {}) { +module.exports = function sleep (user) { user.preferences.sleep = !user.preferences.sleep; - if (req.v2 === true) { - return {}; - } else { - return [user.preferences.sleep]; - } + return [user.preferences.sleep]; }; diff --git a/website/common/script/ops/unlock.js b/website/common/script/ops/unlock.js index d9f4ec812c..1afe2623fe 100644 --- a/website/common/script/ops/unlock.js +++ b/website/common/script/ops/unlock.js @@ -111,9 +111,5 @@ module.exports = function unlock (user, req = {}, analytics) { if (!alreadyOwns) response.push(i18n.t('unlocked', req.language)); - if (req.v2 === true) { - return response[0]; - } else { - return response; - } + return response; }; diff --git a/website/common/script/ops/update.js b/website/common/script/ops/update.js deleted file mode 100644 index c41e74180e..0000000000 --- a/website/common/script/ops/update.js +++ /dev/null @@ -1,11 +0,0 @@ -import _ from 'lodash'; - -// TODO used only in client, move there? - -module.exports = function updateUser (user, req = {}) { - _.each(req.body, (val, key) => { - _.set(user, key, val); - }); - - return user; -}; diff --git a/website/common/script/ops/updateWebhook.js b/website/common/script/ops/updateWebhook.js index 63fed89b17..185f6ad404 100644 --- a/website/common/script/ops/updateWebhook.js +++ b/website/common/script/ops/updateWebhook.js @@ -12,9 +12,5 @@ module.exports = function updateWebhook (user, req) { user.preferences.webhooks[req.params.id].url = req.body.url; user.preferences.webhooks[req.params.id].enabled = req.body.enabled; - if (req.v2 === true) { - return user.preferences.webhooks; - } else { - return [user.preferences.webhooks[req.params.id]]; - } + return [user.preferences.webhooks[req.params.id]]; }; diff --git a/website/server/controllers/api-v3/user.js b/website/server/controllers/api-v3/user.js index 5aaf7015e5..e6844a3148 100644 --- a/website/server/controllers/api-v3/user.js +++ b/website/server/controllers/api-v3/user.js @@ -537,7 +537,7 @@ api.allocateNow = { url: '/user/allocate-now', async handler (req, res) { let user = res.locals.user; - let allocateNowRes = common.ops.allocateNow(user, req); + let allocateNowRes = common.ops.allocateNow(user); await user.save(); res.respond(200, ...allocateNowRes); }, @@ -1241,7 +1241,7 @@ api.markPmsRead = { url: '/user/mark-pms-read', async handler (req, res) { let user = res.locals.user; - let markPmsResponse = common.ops.markPmsRead(user, req); + let markPmsResponse = common.ops.markPmsRead(user); await user.save(); res.respond(200, markPmsResponse); }, @@ -1308,7 +1308,7 @@ api.userReset = { ], }).select('_id type challenge').exec(); - let resetRes = common.ops.reset(user, tasks, req); + let resetRes = common.ops.reset(user, tasks); await Bluebird.all([ Tasks.Task.remove({_id: {$in: resetRes[0].tasksToRemove}, userId: user._id}),