Adjust NotGonnaGitUs's PR

* move challenge test to separate file
* adjust wording of popover text
* prevent refunding gems for tavern challenges
* adjust ui of challenge creation page
* fix bug in cancel function
* adjust wording of delete confirmation message
This commit is contained in:
Blade Barringer
2015-05-24 20:51:42 -05:00
parent 120872ffd2
commit abbfdaeda5
6 changed files with 84 additions and 887 deletions

View File

@@ -300,24 +300,18 @@ 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){
chal = _chal;
function(chal, cb){
if (!chal) return cb('Challenge ' + cid + ' not found');
if (chal.leader != user._id) return cb("You don't have permissions to edit this challenge");
//Refunds to challenge leader
User.findById(user._id, cb)
},
function(leader, cb){
leader.balance += chal.prize/4;
leader.save(cb);
if (chal.group != 'habitrpg') user.balance += chal.prize/4; // Refund gems to user if a non-tavern challenge
user.save(cb);
},
function(save, num, cb){
//Deletes challenge and adds broken link (same as before) add prizeRefundedTo: save.profile.name?
closeChal(req.params.cid, {broken: 'CHALLENGE_DELETED'}, cb);
}
], function(err){