remove challangeMap
move to challenges router
This commit is contained in:
@ -45,23 +45,17 @@ module.exports = function(app) {
|
|||||||
var Challenge = app.models.Challenge;
|
var Challenge = app.models.Challenge;
|
||||||
var User = app.models.User;
|
var User = app.models.User;
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/challenges/next-challenge',
|
|
||||||
userMigration,
|
|
||||||
returnNextChallenge
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/challenges/:challengeName',
|
|
||||||
userMigration,
|
|
||||||
returnIndividualChallenge
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get('/challenges/', userMigration, returnCurrentChallenge);
|
|
||||||
router.post('/completed-challenge/', completedChallenge);
|
router.post('/completed-challenge/', completedChallenge);
|
||||||
router.post('/completed-zipline-or-basejump', completedZiplineOrBasejump);
|
router.post('/completed-zipline-or-basejump', completedZiplineOrBasejump);
|
||||||
router.post('/completed-bonfire', completedBonfire);
|
router.post('/completed-bonfire', completedBonfire);
|
||||||
|
|
||||||
|
// the follow routes are covered by userMigration
|
||||||
|
router.use(userMigration);
|
||||||
|
router.get('/challenges/next-challenge', returnNextChallenge);
|
||||||
|
router.get('/challenges/:challengeName', returnIndividualChallenge);
|
||||||
|
router.get('/challenges/', returnCurrentChallenge);
|
||||||
|
router.get('/map', challengeMap);
|
||||||
|
|
||||||
app.use(router);
|
app.use(router);
|
||||||
|
|
||||||
function returnNextChallenge(req, res, next) {
|
function returnNextChallenge(req, res, next) {
|
||||||
@ -533,4 +527,51 @@ module.exports = function(app) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function challengeMap(req, res, next) {
|
||||||
|
var completedList = [];
|
||||||
|
|
||||||
|
if (req.user) {
|
||||||
|
completedList = req.user.completedChallenges;
|
||||||
|
}
|
||||||
|
|
||||||
|
var noDuplicatedChallenges = R.uniq(completedList);
|
||||||
|
|
||||||
|
var completedChallengeList = noDuplicatedChallenges
|
||||||
|
.map(function(challenge) {
|
||||||
|
// backwards compatibility
|
||||||
|
return (challenge.id || challenge._id);
|
||||||
|
});
|
||||||
|
var challengeList = utils.
|
||||||
|
getChallengeMapForDisplay(completedChallengeList);
|
||||||
|
|
||||||
|
Object.keys(challengeList).forEach(function(key) {
|
||||||
|
challengeList[key].completed = challengeList[key]
|
||||||
|
.challenges.filter(function(elem) {
|
||||||
|
// backwards compatibility hack
|
||||||
|
return completedChallengeList.indexOf(elem.id || elem._id) > -1;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function numberWithCommas(x) {
|
||||||
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||||
|
}
|
||||||
|
|
||||||
|
var date1 = new Date('10/15/2014');
|
||||||
|
var date2 = new Date();
|
||||||
|
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
|
||||||
|
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
||||||
|
|
||||||
|
User.count(function(err, camperCount) {
|
||||||
|
if (err) { return next(err); }
|
||||||
|
|
||||||
|
res.render('challengeMap/show', {
|
||||||
|
daysRunning: daysRunning,
|
||||||
|
camperCount: numberWithCommas(camperCount),
|
||||||
|
title: "A map of all Free Code Camp's Challenges",
|
||||||
|
challengeList: challengeList,
|
||||||
|
completedChallengeList: completedChallengeList
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
var R = require('ramda'),
|
|
||||||
// debug = require('debug')('freecc:cntr:challengeMap'),
|
|
||||||
utils = require('./../utils'),
|
|
||||||
middleware = require('../utils/middleware');
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(app) {
|
|
||||||
var User = app.models.User;
|
|
||||||
var router = app.loopback.Router();
|
|
||||||
|
|
||||||
router.get('/map', middleware.userMigration, challengeMap);
|
|
||||||
router.get('/learn-to-code', function(req, res) {
|
|
||||||
res.redirect(301, '/map');
|
|
||||||
});
|
|
||||||
router.get('/about', function(req, res) {
|
|
||||||
res.redirect(301, '/map');
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(router);
|
|
||||||
|
|
||||||
function challengeMap(req, res, next) {
|
|
||||||
var completedList = [];
|
|
||||||
|
|
||||||
if (req.user) {
|
|
||||||
completedList = req.user.completedChallenges;
|
|
||||||
}
|
|
||||||
|
|
||||||
var noDuplicatedChallenges = R.uniq(completedList);
|
|
||||||
|
|
||||||
var completedChallengeList = noDuplicatedChallenges
|
|
||||||
.map(function(challenge) {
|
|
||||||
return (challenge.id || challenge._id); // backwards compatibility
|
|
||||||
});
|
|
||||||
var challengeList = utils.
|
|
||||||
getChallengeMapForDisplay(completedChallengeList);
|
|
||||||
|
|
||||||
Object.keys(challengeList).forEach(function(key) {
|
|
||||||
challengeList[key].completed = challengeList[key]
|
|
||||||
.challenges.filter(function(elem) {
|
|
||||||
return completedChallengeList.indexOf(elem.id || elem._id) > -1;
|
|
||||||
//backwards compatibility hack
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function numberWithCommas(x) {
|
|
||||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
||||||
}
|
|
||||||
|
|
||||||
var date1 = new Date('10/15/2014');
|
|
||||||
var date2 = new Date();
|
|
||||||
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
|
|
||||||
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
|
||||||
|
|
||||||
User.count(function(err, camperCount) {
|
|
||||||
if (err) { return next(err); }
|
|
||||||
|
|
||||||
res.render('challengeMap/show', {
|
|
||||||
daysRunning: daysRunning,
|
|
||||||
camperCount: numberWithCommas(camperCount),
|
|
||||||
title: "A map of all Free Code Camp's Challenges",
|
|
||||||
challengeList: challengeList,
|
|
||||||
completedChallengeList: completedChallengeList
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
@ -18,5 +18,13 @@ module.exports = function(app) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/learn-to-code', function(req, res) {
|
||||||
|
res.redirect(301, '/map');
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/about', function(req, res) {
|
||||||
|
res.redirect(301, '/map');
|
||||||
|
});
|
||||||
|
|
||||||
app.use(router);
|
app.use(router);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user