From 3f690629b0530ed3ab2b371d2c0bb46c4abbb78d Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Thu, 21 May 2015 00:17:44 -0700 Subject: [PATCH] Fix add missing return add notes --- controllers/challenge.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/controllers/challenge.js b/controllers/challenge.js index 40b0b13089..2c31c561ab 100644 --- a/controllers/challenge.js +++ b/controllers/challenge.js @@ -139,7 +139,7 @@ exports.returnIndividualChallenge = function(req, res, next) { Challenge.find({'name': new RegExp(challengeName, 'i')}, function(err, challengeFromMongo) { if (err) { - next(err); + return next(err); } // Handle not found if (challengeFromMongo.length < 1) { @@ -292,8 +292,8 @@ exports.completedBonfire = function (req, res, next) { var challengeName = req.body.challengeInfo.challengeName; if (isCompletedWith) { - var paired = User.find({'profile.username': isCompletedWith - .toLowerCase()}).limit(1); + var paired = User.find({'profile.username': isCompletedWith.toLowerCase()}) + .limit(1); paired.exec(function (err, pairedWith) { if (err) { return next(err); @@ -366,6 +366,7 @@ exports.completedBonfire = function (req, res, next) { if (err) { return next(err); } + // NOTE(berks): Under certain conditions the res is never ended if (user) { res.send(true); } @@ -420,7 +421,9 @@ exports.completedZiplineOrBasejump = function (req, res, next) { } if (isCompletedWith) { - var paired = User.find({'profile.username': isCompletedWith.toLowerCase()}).limit(1); + var paired = User.find({'profile.username': isCompletedWith.toLowerCase()}) + .limit(1); + paired.exec(function (err, pairedWithFromMongo) { if (err) { return next(err); @@ -499,6 +502,7 @@ exports.completedZiplineOrBasejump = function (req, res, next) { if (err) { return next(err); } + // NOTE(berks): under certain conditions this will not close the response. if (user) { return res.sendStatus(200); }