April 2020
Intermediate to advanced
716 pages
18h 55m
English
For the implementation of the create shop API that will allow creating new shops in the database, we will first add a POST route, as shown in the following code:
mern-marketplace/server/routes/shop.routes.js:
router.route('/api/shops/by/:userId') .post(authCtrl.requireSignin, authCtrl.hasAuthorization, userCtrl.isSeller, shopCtrl.create)
A POST request to this route at /api/shops/by/:userId will first ensure the requesting user is signed in and is also the authorized owner, in other words, it is the same user associated with the :userId specified in the route param.
To process the :userId param and retrieve the associated user from the database, we will utilize the userByID method in the user controller. We will add the ...
Read now
Unlock full access