Merge pull request #214 from MrRenter/upvoteFix

Upvote fix
This commit is contained in:
Quincy Larson
2015-03-17 15:48:15 -07:00
3 changed files with 19 additions and 4 deletions

View File

@@ -139,7 +139,18 @@ exports.returnIndividualStory = function(req, res, next) {
return res.redirect('../stories/' + dashedNameFull);
}
res.render('stories/index', {
var userVoted = false;
try {
var votedObj = story.upVotes.filter(function(a){
return a['upVotedByUsername'] === req.user['profile']['username'];
})
if (votedObj.length > 0){
userVoted = true;
}
} catch(err){
userVoted = false;
}
res.render('stories/index', {
title: story.headline,
link: story.link,
author: story.author,
@@ -152,7 +163,8 @@ exports.returnIndividualStory = function(req, res, next) {
timeAgo: moment(story.timePosted).fromNow(),
image: story.image,
page: 'show',
storyMetaDescription: story.metaDescription
storyMetaDescription: story.metaDescription,
hasUserVoted: userVoted
});
});
};