Create shop API

In the backend, we will add a POST route that verifies that the current user is a seller and creates a new shop with the shop data passed in the request.

mern-marketplace/server/routes/shop.routes.js:

router.route('/api/shops/by/:userId')    .post(authCtrl.requireSignin,authCtrl.hasAuthorization,            userCtrl.isSeller, shopCtrl.create)

The shop.routes.js file will be very similar to the user.routes file, and to load these new routes in the Express app, we need to mount the shop routes in express.js, like we did for the auth and user routes.

mern-marketplace/server/express.js:

app.use('/', shopRoutes)

We will update the user controller to add the isSeller method, this will ensure the current user is actually a seller before creating ...

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.