Refactor Purchase API - Part 1 (#9714)

* move to shops/purchase

* move files to /buy/ instead of /purchase/

* refactor buy.js - add more itemtypes

* revert moving special purchases to buy

* only use buyOp from api-routes

* fix buying potion client-side

* undo import buy instead of purchase

* enable potion bulk purchase - use buyGear as fallback (as before)

* move quantity purchase inside buyHealthPotion

* move quantity purchase inside buyQuest

* move quantity purchase inside buySpecialSpell + add analytics

* remove unused quantity variable - set req.type on specialKeys

* fix `buyKnownKeys` on buy api

* test buy-special-spell if not enough gold

* more buy ops coverage

* fix lint

* buyMysterySet: test for window.confirm, buyQuest: check for Masterclassers unlock

* fix test & lint

* re-create package-lock.json to travis build ?

* use global.window instead of method argument

* add back canOwn checks

* remove buyMysterySet confirm request
This commit is contained in:
negue
2018-02-10 11:14:40 +01:00
committed by Matteo Pagliazzi
parent 7abfd1d510
commit 54153ec299
27 changed files with 340 additions and 181 deletions

View File

@@ -744,6 +744,9 @@ api.sleep = {
},
};
const buySpecialKeys = ['snowball', 'spookySparkles', 'shinySeed', 'seafoam'];
const buyKnownKeys = ['armoire', 'mystery', 'potion', 'quest', 'special'];
/**
* @api {post} /api/v3/user/buy/:key Buy gear, armoire or potion
* @apiDescription Under the hood uses UserBuyGear, UserBuyPotion and UserBuyArmoire
@@ -781,14 +784,13 @@ api.buy = {
let user = res.locals.user;
let buyRes;
let specialKeys = ['snowball', 'spookySparkles', 'shinySeed', 'seafoam'];
// @TODO: Remove this when mobile passes type in body
let type = req.params.key;
if (specialKeys.indexOf(req.params.key) !== -1) {
type = 'special';
if (buySpecialKeys.indexOf(type) !== -1) {
req.type = 'special';
} else if (buyKnownKeys.indexOf(type) === -1) {
req.type = 'marketGear';
}
req.type = type;
// @TODO: right now common follow express structure, but we should decouple the dependency
if (req.body.type) req.type = req.body.type;
@@ -1267,7 +1269,7 @@ api.purchase = {
if (req.body.quantity) quantity = req.body.quantity;
req.quantity = quantity;
let purchaseRes = common.ops.purchaseWithSpell(user, req, res.analytics);
let purchaseRes = common.ops.buy(user, req, res.analytics);
await user.save();
res.respond(200, ...purchaseRes);
},
@@ -1298,7 +1300,7 @@ api.userPurchaseHourglass = {
url: '/user/purchase-hourglass/:type/:key',
async handler (req, res) {
let user = res.locals.user;
let purchaseHourglassRes = common.ops.purchaseHourglass(user, req, res.analytics);
let purchaseHourglassRes = common.ops.buy(user, req, res.analytics);
await user.save();
res.respond(200, ...purchaseHourglassRes);
},