feat(coupons): cleaner lookup/validation of coupon code

This commit is contained in:
Tyler Renelle 2014-04-17 17:36:10 -06:00
parent 5af5314a8d
commit 39b5176c1c
2 changed files with 2 additions and 17 deletions

View file

@ -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) {

View file

@ -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':