We will add a GET route to retrieve the shops owned by a specific user to the shop routes declared in the backend.
mern-marketplace/server/routes/shop.routes.js:
router.route('/api/shops/by/:userId') .get(authCtrl.requireSignin, authCtrl.hasAuthorization, shopCtrl.listByOwner)
To process the :userId param and retrieve the associated user from the database, we will utilize the userByID method in user controller. We will add the following to the Shop routes in shop.routes.js, so the user is available in the request object as profile.
mern-marketplace/server/routes/shop.routes.js:
router.param('userId', userCtrl.userByID)
The listByOwner controller method in shop.controller.js will query the Shop collection in the database ...