April 2020
Intermediate to advanced
716 pages
18h 55m
English
We will implement an API in the backend to return the list of shops of a specific owner, so it can be rendered in the frontend for the end user. We will start by adding a route in the backend to retrieve all the shops created by a given user when the server receives a GET request at /api/shops/by/:userId. This route is declared as shown in the following code:
mern-marketplace/server/routes/shop.routes.js:
router.route('/api/shops/by/:userId') .get(authCtrl.requireSignin, authCtrl.hasAuthorization, shopCtrl.listByOwner)
A GET request to this route will first ensure the requesting user is signed in and is also the authorized owner, before invoking the listByOwner controller method in shop.controller.js. This method ...