Shops by owner API

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 ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.