Advertisement
SejimFU

Untitled

Dec 5th, 2018
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Comment delete function in controller
  2.  
  3. exports.DeleteEventComment = function (req, res) {
  4.    
  5.     const eventId = req.params.event_id;
  6.     const commentId = req.params.comment_id;
  7.  
  8.     Comment.findById(commentId)
  9.          .then(comment => {    
  10.            if(!comment) {
  11.             res.status(404).json({message: 'Could not find comment.'})
  12.            }
  13.            if(comment.author.toString() !== req.userData.userId) {
  14.             res.status(403).json({message: 'You are not authorized to do so.'})
  15.            }
  16.  
  17.              comment.remove();
  18.  
  19.          })
  20.          .then(result => {
  21.             res.status(200).json({message: "Deleted comment"});
  22.          })
  23.          .catch(error => {
  24.             res.status(500).json({
  25.               message: "Deleting comment failed!"
  26.             });
  27.           });
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement