Ported purchase, add unit tests, created new user purchase route, and added tests

This commit is contained in:
Keith Holliday
2016-04-01 08:14:15 -05:00
parent 3089658cc7
commit ad0bc58028
7 changed files with 358 additions and 71 deletions

View File

@@ -676,4 +676,27 @@ api.disableClasses = {
},
};
/**
* @api {post} /user/purchase/:type/:key Purchase Gem Items.
* @apiVersion 3.0.0
* @apiName UserPurchase
* @apiGroup User
*
* @apiParam {string} type Type of item to purchase
* @apiParam {string} key Item's key
*
* @apiSuccess {Object} data `items balance`
*/
api.purchase = {
method: 'POST',
middlewares: [authWithHeaders(), cron],
url: '/user/purchase/:type/:key',
async handler (req, res) {
let user = res.locals.user;
let purchaseResponse = common.ops.purchase(user, req, res.analytics);
await user.save();
res.respond(200, purchaseResponse);
},
};
module.exports = api;