From 39b5176c1c71026a4f26efaf4e7494ef57bb931e Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Thu, 17 Apr 2014 17:36:10 -0600 Subject: [PATCH] feat(coupons): cleaner lookup/validation of coupon code --- src/controllers/coupon.js | 15 --------------- src/models/coupon.js | 4 ++-- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/controllers/coupon.js b/src/controllers/coupon.js index fb1a5c251d..f1a95ad141 100644 --- a/src/controllers/coupon.js +++ b/src/controllers/coupon.js @@ -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) { diff --git a/src/models/coupon.js b/src/models/coupon.js index 8905ed0320..b721331f02 100644 --- a/src/models/coupon.js +++ b/src/models/coupon.js @@ -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':