The unlike API will be implemented similar to the like API, with its own route at mern-social/server/routes/post.routes.js:
router.route('/api/posts/unlike') .put(authCtrl.requireSignin, postCtrl.unlike)
The unlike method in the controller will find the post by its ID and update the likes array by removing the current user's ID using $pull instead of $push.
mern-social/server/controllers/post.controller.js:
const unlike = (req, res) => { Post.findByIdAndUpdate(req.body.postId, {$pull: {likes: req.body.userId}}, {new: true}) .exec((err, result) => { if (err) { return res.status(400).json({ error: errorHandler.getErrorMessage(err) }) } res.json(result) })}
The unlike API will also have a corresponding fetch method similar to the ...