Skip to content

Instantly share code, notes, and snippets.

@turbo1912
Last active December 20, 2015 00:29
Show Gist options
  • Save turbo1912/6042558 to your computer and use it in GitHub Desktop.
Save turbo1912/6042558 to your computer and use it in GitHub Desktop.
updating the post type before sending the post to the view..
User.findOne({ twitterID: req.user.id },
function(err, user) {
if (user){
var votedPosts = user.votedPosts;
Post.find(function (err, posts) {
if(posts){
for (var i = 0; i < posts.length; i++){
for (var j = 0; j < votedPosts.length; j++){
if(String(votedPosts[j]._id) == String(posts[i]._id)){
posts[i].votetype = votedPosts[j].votetype;
}
}
if (!posts[i].votetype){
posts[i].votetype = 0;
}
}
res.send(posts);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment