Skip to content

Instantly share code, notes, and snippets.

@calvintwr
Created August 20, 2014 17:18
Show Gist options
  • Save calvintwr/e7b7307a56bb537427bb to your computer and use it in GitHub Desktop.
Save calvintwr/e7b7307a56bb537427bb to your computer and use it in GitHub Desktop.
if(req.body.action == 'unlike') {
//using find a
db.Like.findAll({
where: db.Sequelize.and(
{Post_postId: req.body.postId},
{User_userId: req.user.userId}
)
}).then(function(likes) {
console.log(likes);
// console.log(likes.length);
if(likes.length > 0) {
var idArray = [];
for(var i in likes) {
idArray.push(likes[i].values['likeId']);
}
db.Like.destroy({likeId: idArray}).then(function(){
return eventEmitter.emit('addRemoveLikeDone', true);
});
} else {
console.log('attempt to unlike a post has not been liked');
return eventEmitter.emit('addRemoveLikeDone', false);
}
}).catch(function(err) {
console.log('caught error:');
console.log(err);
return eventEmitter.emit('addRemoveLikeDone', false);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment