mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-27 00:59:42 +00:00
34 lines
911 B
JavaScript
34 lines
911 B
JavaScript
|
|
import { authWithHeaders } from '../../middlewares/auth';
|
||
|
|
import * as couponsLib from '../../libs/coupons';
|
||
|
|
|
||
|
|
/*
|
||
|
|
* NOTE most coupons routes are still in the v3 controller
|
||
|
|
* here there are only routes that had to be split from the v3 version because of
|
||
|
|
* some breaking change (for example because their returned the entire user object).
|
||
|
|
*/
|
||
|
|
|
||
|
|
const api = {};
|
||
|
|
|
||
|
|
/* NOTE this route has also an API v3 version */
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @api {post} /api/v4/coupons/enter/:code Redeem a coupon code
|
||
|
|
* @apiName RedeemCouponCode
|
||
|
|
* @apiGroup Coupon
|
||
|
|
*
|
||
|
|
* @apiParam (Path) {String} code The coupon code to apply
|
||
|
|
*
|
||
|
|
* @apiSuccess {Object} data User object
|
||
|
|
*/
|
||
|
|
api.enterCouponCode = {
|
||
|
|
method: 'POST',
|
||
|
|
url: '/coupons/enter/:code',
|
||
|
|
middlewares: [authWithHeaders()],
|
||
|
|
async handler (req, res) {
|
||
|
|
const user = res.locals.user;
|
||
|
|
await couponsLib.enterCode(req, res, user);
|
||
|
|
res.respond(200, user);
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
module.exports = api;
|