mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Ported purchase, add unit tests, created new user purchase route, and added tests
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user