Gems are now refunded to challenge leader on deletion. Needs better description in "broken" field.

This commit is contained in:
NotGonnaGitUs
2015-05-04 02:33:59 +05:30
parent 0454938303
commit 46cb0240c3
2 changed files with 14 additions and 3 deletions

View File

@@ -300,14 +300,21 @@ function closeChal(cid, broken, cb) {
api['delete'] = function(req, res, next){
var user = res.locals.user;
var cid = req.params.cid;
var chal
async.waterfall([
function(cb){
Challenge.findById(cid, cb);
},
function(chal, cb){
function(_chal, cb){
chal = _chal;
if (!chal) return cb('Challenge ' + cid + ' not found');
if (chal.leader != user._id) return cb("You don't have permissions to edit this challenge");
closeChal(req.params.cid, {broken: 'CHALLENGE_DELETED'}, cb);
User.findById(user._id, cb) //Refunds to challenge leader
},
function(leader, cb){
leader.balance += chal.prize/4;
leader.save(cb);
closeChal(req.params.cid, {broken: 'CHALLENGE_DELETED'}, cb); //Not descriptive enough
}
], function(err){
if (err) return next(err);