Added start of individual post view and post lists view, wired upvoting functionality for individual posts

This commit is contained in:
Nathan Leniz
2015-03-03 22:03:33 +09:00
parent 94bbb7a4a5
commit 4b84b49d07
8 changed files with 307 additions and 26 deletions

View File

@@ -50,9 +50,10 @@ exports.returnIndividualStory = function(req, res, next) {
story = story.pop();
var dashedNameFull = story.headline.toLowerCase().replace(/\s/g, '-');
if (dashedNameFull != dashedName) {
if (dashedNameFull !== dashedName) {
return res.redirect('../stories/' + dashedNameFull);
}
debug('Story id is', story._id);
res.render('post/show', {
title: story.headline,
@@ -61,7 +62,21 @@ exports.returnIndividualStory = function(req, res, next) {
body: story.body,
rank: story.rank,
upVotes: story.upVotes,
comments: story.comments
comments: story.comments,
id: story._id
});
});
};
exports.upvote = function(req, res, next) {
var data = req.params.id;
Story.find({'_id': data}, function(err, story) {
if (err) {
throw err;
}
story = story.pop();
story.rank++;
story.save();
return res.send(story);
});
};