Clean up more linting errors and split out returns from Mongo.
This commit is contained in:
@ -63,12 +63,12 @@ exports.returnNextBonfire = function(req, res, next) {
|
|||||||
var uncompletedBonfires = req.user.uncompletedBonfires;
|
var uncompletedBonfires = req.user.uncompletedBonfires;
|
||||||
|
|
||||||
var displayedBonfires = Bonfire.find({'_id': uncompletedBonfires[0]});
|
var displayedBonfires = Bonfire.find({'_id': uncompletedBonfires[0]});
|
||||||
displayedBonfires.exec(function(err, bonfire) {
|
displayedBonfires.exec(function(err, bonfireFromMongo) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
bonfire = bonfire.pop();
|
var bonfire = bonfireFromMongo.pop();
|
||||||
if (bonfire === undefined) {
|
if (typeof bonfire === 'undefined') {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: "It looks like you've completed all the bonfires we have available. Good job!"
|
msg: "It looks like you've completed all the bonfires we have available. Good job!"
|
||||||
});
|
});
|
||||||
@ -84,13 +84,13 @@ exports.returnIndividualBonfire = function(req, res, next) {
|
|||||||
|
|
||||||
var bonfireName = dashedName.replace(/\-/g, ' ');
|
var bonfireName = dashedName.replace(/\-/g, ' ');
|
||||||
|
|
||||||
Bonfire.find({'name': new RegExp(bonfireName, 'i')}, function(err, bonfire) {
|
Bonfire.find({'name': new RegExp(bonfireName, 'i')}, function(err, bonfireFromMongo) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (bonfire.length < 1) {
|
if (bonfireFromMongo.length < 1) {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: "404: We couldn't find a bonfire with that name. Please double check the name."
|
msg: "404: We couldn't find a bonfire with that name. Please double check the name."
|
||||||
});
|
});
|
||||||
@ -98,9 +98,9 @@ exports.returnIndividualBonfire = function(req, res, next) {
|
|||||||
return res.redirect('/bonfires');
|
return res.redirect('/bonfires');
|
||||||
}
|
}
|
||||||
|
|
||||||
bonfire = bonfire.pop();
|
var bonfire = bonfireFromMongo.pop();
|
||||||
var dashedNameFull = bonfire.name.toLowerCase().replace(/\s/g, '-');
|
var dashedNameFull = bonfire.name.toLowerCase().replace(/\s/g, '-');
|
||||||
if (dashedNameFull != dashedName) {
|
if (dashedNameFull !== dashedName) {
|
||||||
return res.redirect('../bonfires/' + dashedNameFull);
|
return res.redirect('../bonfires/' + dashedNameFull);
|
||||||
}
|
}
|
||||||
res.render('bonfire/show', {
|
res.render('bonfire/show', {
|
||||||
|
@ -50,14 +50,14 @@ exports.returnNextCourseware = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
courseware = courseware.pop();
|
courseware = courseware.pop();
|
||||||
if (courseware === undefined) {
|
if (typeof courseware === 'undefined') {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: "It looks like you've completed all the courses we have " +
|
msg: "It looks like you've completed all the courses we have " +
|
||||||
"available. Good job!"
|
"available. Good job!"
|
||||||
});
|
});
|
||||||
return res.redirect('../challenges/learn-how-free-code-camp-works');
|
return res.redirect('../challenges/learn-how-free-code-camp-works');
|
||||||
}
|
}
|
||||||
nameString = courseware.name.toLowerCase().replace(/\s/g, '-');
|
var nameString = courseware.name.toLowerCase().replace(/\s/g, '-');
|
||||||
return res.redirect('../challenges/' + nameString);
|
return res.redirect('../challenges/' + nameString);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -68,23 +68,23 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
|||||||
var coursewareName = dashedName.replace(/\-/g, ' ');
|
var coursewareName = dashedName.replace(/\-/g, ' ');
|
||||||
|
|
||||||
Courseware.find({'name': new RegExp(coursewareName, 'i')},
|
Courseware.find({'name': new RegExp(coursewareName, 'i')},
|
||||||
function(err, courseware) {
|
function(err, coursewareFromMongo) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
// Handle not found
|
// Handle not found
|
||||||
if (courseware.length < 1) {
|
if (coursewareFromMongo.length < 1) {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: "404: We couldn't find a challenge with that name. " +
|
msg: "404: We couldn't find a challenge with that name. " +
|
||||||
"Please double check the name."
|
"Please double check the name."
|
||||||
});
|
});
|
||||||
return res.redirect('/challenges');
|
return res.redirect('/challenges');
|
||||||
}
|
}
|
||||||
courseware = courseware.pop();
|
var courseware = coursewareFromMongo.pop();
|
||||||
|
|
||||||
// Redirect to full name if the user only entered a partial
|
// Redirect to full name if the user only entered a partial
|
||||||
var dashedNameFull = courseware.name.toLowerCase().replace(/\s/g, '-');
|
var dashedNameFull = courseware.name.toLowerCase().replace(/\s/g, '-');
|
||||||
if (dashedNameFull != dashedName) {
|
if (dashedNameFull !== dashedName) {
|
||||||
return res.redirect('../challenges/' + dashedNameFull);
|
return res.redirect('../challenges/' + dashedNameFull);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
|
|||||||
|
|
||||||
if (isCompletedWith) {
|
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) {
|
paired.exec(function (err, pairedWithFromMongo) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
} else {
|
} else {
|
||||||
@ -301,7 +301,7 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
|
|||||||
req.user.progressTimestamps.push(Date.now() || 0);
|
req.user.progressTimestamps.push(Date.now() || 0);
|
||||||
req.user.uncompletedCoursewares.splice(index, 1);
|
req.user.uncompletedCoursewares.splice(index, 1);
|
||||||
}
|
}
|
||||||
pairedWith = pairedWith.pop();
|
var pairedWith = pairedWithFromMongo.pop();
|
||||||
|
|
||||||
req.user.completedCoursewares.push({
|
req.user.completedCoursewares.push({
|
||||||
_id: coursewareHash,
|
_id: coursewareHash,
|
||||||
|
@ -253,7 +253,7 @@ exports.checkExistingUsername = function(req, res, next) {
|
|||||||
exports.checkUniqueEmail = function(req, res, next) {
|
exports.checkUniqueEmail = function(req, res, next) {
|
||||||
User.count({'email': decodeURIComponent(req.params.email).toLowerCase()}, function (err, data) {
|
User.count({'email': decodeURIComponent(req.params.email).toLowerCase()}, function (err, data) {
|
||||||
if (err) { return next(err); }
|
if (err) { return next(err); }
|
||||||
if (data == 1) {
|
if (data === 1) {
|
||||||
return res.send(true);
|
return res.send(true);
|
||||||
} else {
|
} else {
|
||||||
return res.send(false);
|
return res.send(false);
|
||||||
@ -271,7 +271,7 @@ exports.returnUser = function(req, res, next) {
|
|||||||
User.find({'profile.username': req.params.username.toLowerCase()}, function(err, user) {
|
User.find({'profile.username': req.params.username.toLowerCase()}, function(err, user) {
|
||||||
if (err) { debug('Username err: ', err); next(err); }
|
if (err) { debug('Username err: ', err); next(err); }
|
||||||
if (user[0]) {
|
if (user[0]) {
|
||||||
var user = user[0];
|
user = user[0];
|
||||||
|
|
||||||
user.progressTimestamps = user.progressTimestamps.sort(function(a, b) {
|
user.progressTimestamps = user.progressTimestamps.sort(function(a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
@ -284,6 +284,7 @@ exports.returnUser = function(req, res, next) {
|
|||||||
|
|
||||||
var tmpLongest = 1;
|
var tmpLongest = 1;
|
||||||
var timeKeys = R.keys(timeObject);
|
var timeKeys = R.keys(timeObject);
|
||||||
|
|
||||||
for (var i = 1; i <= timeKeys.length; i++) {
|
for (var i = 1; i <= timeKeys.length; i++) {
|
||||||
if (moment(timeKeys[i - 1]).add(1, 'd').toString()
|
if (moment(timeKeys[i - 1]).add(1, 'd').toString()
|
||||||
=== moment(timeKeys[i]).toString()) {
|
=== moment(timeKeys[i]).toString()) {
|
||||||
@ -305,13 +306,17 @@ exports.returnUser = function(req, res, next) {
|
|||||||
|
|
||||||
var data = {};
|
var data = {};
|
||||||
var progressTimestamps = user.progressTimestamps;
|
var progressTimestamps = user.progressTimestamps;
|
||||||
for (var i = 0; i < progressTimestamps.length; i++) {
|
progressTimestamps.forEach(function(timeStamp) {
|
||||||
data[(progressTimestamps[i] / 1000).toString()] = 1;
|
data[(timeStamp / 1000)] = 1;
|
||||||
}
|
});
|
||||||
|
|
||||||
|
//for (var i = 0; i < progressTimestamps.length; i++) {
|
||||||
|
// data[(progressTimestamps[i] / 1000).toString()] = 1;
|
||||||
|
//}
|
||||||
|
|
||||||
user.currentStreak = user.currentStreak || 1;
|
user.currentStreak = user.currentStreak || 1;
|
||||||
user.longestStreak = user.longestStreak || 1;
|
user.longestStreak = user.longestStreak || 1;
|
||||||
challenges = user.completedCoursewares.filter(function ( obj ) {
|
var challenges = user.completedCoursewares.filter(function ( obj ) {
|
||||||
return !!obj.solution;
|
return !!obj.solution;
|
||||||
});
|
});
|
||||||
res.render('account/show', {
|
res.render('account/show', {
|
||||||
|
Reference in New Issue
Block a user