Created
August 20, 2014 17:18
-
-
Save calvintwr/e7b7307a56bb537427bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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