mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-14 07:52:15 +00:00
feat(coupons): cleaner lookup/validation of coupon code
This commit is contained in:
parent
5af5314a8d
commit
39b5176c1c
2 changed files with 2 additions and 17 deletions
|
|
@ -15,21 +15,6 @@ api.generateCoupons = function(req,res,next) {
|
|||
if(err) return next(err);
|
||||
res.send(200);
|
||||
});
|
||||
|
||||
// var skip, count=req.params.count || 1;
|
||||
// async.waterfall([
|
||||
// function(cb) {
|
||||
// Coupon.findOne({}, {}, {sort: '-seq'}, cb);
|
||||
// },
|
||||
// function(_lastCoupon,cb){
|
||||
// skip = _lastCoupon ? _lastCoupon.seq : 0;
|
||||
// Coupon.generate(req.params.event, count, cb);
|
||||
// }
|
||||
// ], function(err){
|
||||
// if (err) return next(err);
|
||||
// //res.redirect('/api/v2/coupons?skip='+skip+'&limit='+count);
|
||||
// res.send(200);
|
||||
// })
|
||||
}
|
||||
|
||||
api.getCoupons = function(req,res,next) {
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ CouponSchema.statics.apply = function(user, code, next){
|
|||
var _coupon,_user;
|
||||
async.waterfall([
|
||||
function(cb) {
|
||||
mongoose.model('Coupon').findById(code, cb);
|
||||
mongoose.model('Coupon').findById(cc.validate(code), cb);
|
||||
},
|
||||
function(coupon, cb) {
|
||||
_coupon = coupon;
|
||||
if (_.isEmpty(cc.validate(code)) || !coupon) return cb("Invalid coupon code");
|
||||
if (!coupon) return cb("Invalid coupon code");
|
||||
if (coupon.user) return cb("Coupon already used");
|
||||
switch (coupon.event) {
|
||||
case 'wondercon':
|
||||
|
|
|
|||
Loading…
Reference in a new issue