Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Comment delete function in controller
- exports.DeleteEventComment = function (req, res) {
- const eventId = req.params.event_id;
- const commentId = req.params.comment_id;
- Comment.findById(commentId)
- .then(comment => {
- if(!comment) {
- res.status(404).json({message: 'Could not find comment.'})
- }
- if(comment.author.toString() !== req.userData.userId) {
- res.status(403).json({message: 'You are not authorized to do so.'})
- }
- comment.remove();
- })
- .then(result => {
- res.status(200).json({message: "Deleted comment"});
- })
- .catch(error => {
- res.status(500).json({
- message: "Deleting comment failed!"
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement