reduce user saves, provide callbacks.
This commit is contained in:
@ -109,19 +109,27 @@ exports.returnCurrentChallenge = function(req, res, next) {
|
|||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
req.user.save();
|
|
||||||
if (!req.user.currentChallenge) {
|
if (!req.user.currentChallenge) {
|
||||||
req.user.currentChallenge = {};
|
req.user.currentChallenge = {};
|
||||||
req.user.currentChallenge.challengeId = challengeMapWithIds['0'][0];
|
req.user.currentChallenge.challengeId = challengeMapWithIds['0'][0];
|
||||||
req.user.currentChallenge.challengeName = challengeMapWithNames['0'][0];
|
req.user.currentChallenge.challengeName = challengeMapWithNames['0'][0];
|
||||||
req.user.currentChallenge.challengeBlock = '0';
|
req.user.currentChallenge.challengeBlock = '0';
|
||||||
req.user.save();
|
req.user.save(function(err) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
return res.redirect('../challenges/learn-how-free-code-camp-works');
|
return res.redirect('../challenges/learn-how-free-code-camp-works');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
var nameString = req.user.currentChallenge.challengeName.trim()
|
var nameString = req.user.currentChallenge.challengeName.trim()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/\s/g, '-');
|
.replace(/\s/g, '-');
|
||||||
|
req.user.save(function(err) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
return res.redirect('../challenges/' + nameString);
|
return res.redirect('../challenges/' + nameString);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.returnIndividualChallenge = function(req, res, next) {
|
exports.returnIndividualChallenge = function(req, res, next) {
|
||||||
@ -163,7 +171,6 @@ exports.returnIndividualChallenge = function(req, res, next) {
|
|||||||
))
|
))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
req.user.save();
|
|
||||||
|
|
||||||
var challengeType = {
|
var challengeType = {
|
||||||
0: function() {
|
0: function() {
|
||||||
@ -269,9 +276,12 @@ exports.returnIndividualChallenge = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
req.user.save(function(err) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
return challengeType[challenge.challengeType]();
|
return challengeType[challenge.challengeType]();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user