merge pr for unique story slugs
This commit is contained in:
@ -109,8 +109,8 @@ exports.returnIndividualBonfire = function(req, res, next) {
|
||||
dashedName: dashedName,
|
||||
name: bonfire.name,
|
||||
difficulty: Math.floor(+bonfire.difficulty),
|
||||
brief: bonfire.description[0],
|
||||
details: bonfire.description.slice(1),
|
||||
brief: bonfire.description.shift(),
|
||||
details: bonfire.description,
|
||||
tests: bonfire.tests,
|
||||
challengeSeed: bonfire.challengeSeed,
|
||||
points: req.user ? req.user.points : undefined,
|
||||
|
@ -120,7 +120,7 @@ exports.returnIndividualStory = function(req, res, next) {
|
||||
|
||||
var storyName = dashedName.replace(/\-/g, ' ');
|
||||
|
||||
Story.find({'storyLink': new RegExp(storyName, 'i')}, function(err, story) {
|
||||
Story.find({'storyLink': storyName}, function(err, story) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@ -324,6 +324,18 @@ exports.storySubmission = function(req, res, next) {
|
||||
.replace(/[^a-z0-9]/gi, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.toLowerCase();
|
||||
var link = data.link;
|
||||
if (link.search(/^https?:\/\//g) === -1) {
|
||||
link = 'http://' + link;
|
||||
}
|
||||
Story.count({'storyLink': new RegExp('^' + storyLink + '(?: [0-9]+)?$', 'i')}, function (err, storyCount) {
|
||||
if (err) {
|
||||
return res.status(500);
|
||||
}
|
||||
|
||||
// if duplicate storyLink add unique number
|
||||
storyLink = (storyCount == 0) ? storyLink : storyLink + ' ' + storyCount;
|
||||
|
||||
var link = data.link;
|
||||
if (link.search(/^https?:\/\//g) === -1) {
|
||||
link = 'http://' + link;
|
||||
@ -356,8 +368,7 @@ exports.storySubmission = function(req, res, next) {
|
||||
metaDescription: data.storyMetaDescription,
|
||||
originalStoryAuthorEmail: req.user.email
|
||||
});
|
||||
|
||||
story.save(function(err) {
|
||||
story.save(function (err) {
|
||||
if (err) {
|
||||
return res.status(500);
|
||||
}
|
||||
@ -365,9 +376,10 @@ exports.storySubmission = function(req, res, next) {
|
||||
storyLink: story.storyLink.replace(/\s/g, '-').toLowerCase()
|
||||
}));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.commentSubmit = function(req, res, next) {
|
||||
exports.commentSubmit = function(req, res, next) {
|
||||
var data = req.body.data;
|
||||
if (!req.user) {
|
||||
return next(new Error('Not authorized'));
|
||||
@ -402,9 +414,9 @@ exports.commentSubmit = function(req, res, next) {
|
||||
});
|
||||
|
||||
commentSave(comment, Story, res, next);
|
||||
};
|
||||
};
|
||||
|
||||
exports.commentOnCommentSubmit = function(req, res, next) {
|
||||
exports.commentOnCommentSubmit = function(req, res, next) {
|
||||
var data = req.body.data;
|
||||
if (!req.user) {
|
||||
return next(new Error('Not authorized'));
|
||||
@ -439,9 +451,9 @@ exports.commentOnCommentSubmit = function(req, res, next) {
|
||||
commentOn: Date.now()
|
||||
});
|
||||
commentSave(comment, Comment, res, next);
|
||||
};
|
||||
};
|
||||
|
||||
exports.commentEdit = function(req, res, next) {
|
||||
exports.commentEdit = function(req, res, next) {
|
||||
|
||||
Comment.find({'_id': req.params.id}, function(err, cmt) {
|
||||
if (err) {
|
||||
@ -476,9 +488,9 @@ exports.commentEdit = function(req, res, next) {
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
function commentSave(comment, Context, res, next) {
|
||||
function commentSave(comment, Context, res, next) {
|
||||
comment.save(function(err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@ -538,4 +550,4 @@ function commentSave(comment, Context, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -728,8 +728,9 @@
|
||||
"Create a function that takes two or more arrays and returns an array of the symmetric difference of the provided arrays.",
|
||||
"The mathematical term symmetric difference refers to the elements in two sets that are in either the first or second set, but not in both."
|
||||
],
|
||||
"challengeSeed": "function sym(args) {\n return arr;\r\n}\n\nsym([1, 2, 3], [5, 2, 1, 4]);",
|
||||
"challengeSeed": "function sym(args) {\n return arguments;\r\n}\n\nsym([1, 2, 3], [5, 2, 1, 4]);",
|
||||
"tests": [
|
||||
"expect(sym([1, 2, 3], [5, 2, 1, 4])).to.eqls([3, 5, 4])",
|
||||
"assert.deepEqual(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]), [1, 4, 5], 'should return the symmetric difference of the given arrays');",
|
||||
"assert.deepEqual(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]), [1, 4, 5], 'should return an array of unique values');",
|
||||
"assert.deepEqual(sym([1, 1]), [1], 'should return an array of unique values');"
|
||||
|
Reference in New Issue
Block a user