May 2018
Intermediate to advanced
470 pages
13h 54m
English
We will implement an uncomment API at the following PUT route.
mern-social/server/routes/post.routes.js:
router.route('/api/posts/uncomment') .put(authCtrl.requireSignin, postCtrl.uncomment)
The uncomment controller method will find the relevant post by ID, then pull the comment with the deleted comment's ID from the comments array in the post.
mern-social/server/controllers/post.controller.js:
const uncomment = (req, res) => { let comment = req.body.comment Post.findByIdAndUpdate(req.body.postId, {$pull: {comments: {_id: comment._id}}}, {new: true}) .populate('comments.postedBy', '_id name') .populate('postedBy', '_id name') .exec((err, result) => { if (err) { return res.status(400).json({ error: errorHandler.getErrorMessage(err) ...Read now
Unlock full access