April 2020
Intermediate to advanced
716 pages
18h 55m
English
To retrieve posts that have been shared by a specific user, we need to add a route endpoint that will receive the request for these posts and respond accordingly to the requesting client- side.
On the backend, we will define another post-related route that will receive a query to return posts by a specific user, as follows.
mern-social/server/routes/post.routes.js:
router.route('/api/posts/by/:userId') .get(authCtrl.requireSignin, postCtrl.listByUser)
The listByUser controller method in post.controller.js will query the Post collection to find posts that have a matching reference in the postedBy field to the user specified in the userId param in the route. The listByUser controller method will look as follows.
mern-social/server ...
Read now
Unlock full access