April 2020
Intermediate to advanced
716 pages
18h 55m
English
For the implementation of the backend API, which will allow us to create a new auction in the database, we will declare a POST route, as shown in the following code.
mern-marketplace/server/routes/auction.routes.js:
router.route('/api/auctions/by/:userId') .post(authCtrl.requireSignin, authCtrl.hasAuthorization, userCtrl.isSeller, auctionCtrl.create)
A POST request to this route at /api/auctions/by/:userId will ensure the requesting user is signed in and is also authorized. In other words, it is the same user associated with the :userId specified in the route param. Then, before creating the auction, it is checked if this given user is a seller using the isSeller method that's defined in the user controller methods. ...