move to dashedName lookup
This commit is contained in:
@ -171,40 +171,24 @@ module.exports = function(app) {
|
||||
function returnIndividualChallenge(req, res, next) {
|
||||
var dashedName = req.params.challengeName;
|
||||
|
||||
var challengeName =
|
||||
(/^(bonfire|waypoint|zipline|basejump)/i).test(dashedName) ?
|
||||
dashedName
|
||||
.replace(/\-/g, ' ')
|
||||
.split(' ')
|
||||
.slice(1)
|
||||
.join(' ') :
|
||||
dashedName.replace(/\-/g, ' ');
|
||||
|
||||
Challenge.find(
|
||||
{ where: { name: new RegExp(challengeName, 'i') } },
|
||||
function(err, challengeFromMongo) {
|
||||
Challenge.findOne(
|
||||
{ dashedName: challengeName },
|
||||
function(err, challenge) {
|
||||
if (err) { return next(err); }
|
||||
|
||||
// Handle not found
|
||||
if (challengeFromMongo.length < 1) {
|
||||
if (!challengeFromMongo) {
|
||||
req.flash('errors', {
|
||||
msg: '404: We couldn\'t find a challenge with that name. ' +
|
||||
'Please double check the name.'
|
||||
});
|
||||
return res.redirect('/challenges');
|
||||
}
|
||||
var challenge = challengeFromMongo.pop();
|
||||
// Redirect to full name if the user only entered a partial
|
||||
var dashedNameFull = challenge.name
|
||||
.toLowerCase()
|
||||
.replace(/\s/g, '-')
|
||||
.replace(/[^a-z0-9\-\.]/gi, '');
|
||||
if (dashedNameFull !== dashedName) {
|
||||
return res.redirect('../challenges/' + dashedNameFull);
|
||||
} else if (req.user) {
|
||||
if (req.user) {
|
||||
req.user.currentChallenge = {
|
||||
challengeId: challenge.id,
|
||||
challengeName: challenge.name,
|
||||
challengeName: challenge.dashedName,
|
||||
challengeBlock: R.head(R.flatten(Object.keys(challengeMapWithIds).
|
||||
map(function (key) {
|
||||
return challengeMapWithIds[key]
|
||||
|
Reference in New Issue
Block a user