Create order API

The create order API route is declared in server/routes/order.routes.js. The order routes will be very similar to the user routes. To load the order routes in the Express app, we need to mount the routes in express.js, like we did for the auth and user routes.

mern-marketplace/server/express.js:

app.use('/', orderRoutes)

A number of actions, in the following sequence, take place when the create order API receives a POST request at /api/orders/:userId:

  • It is ensured that the user is signed in
  • A Stripe Customer is either created or updated using the stripeCustomer user controller method discussed earlier
  • The stock quantities are updated for all the ordered products using the decreaseQuanity product controller method
  • The order ...

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.