Get status values

The possible status values of an ordered product are set as enums in the CartItem schema, and to show these values as options in the dropdown view, we will set up a GET API route at /api/order/status_values that retrieves these values.

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

router.route('/api/order/status_values')    .get(orderCtrl.getStatusValues)

The getStatusValues controller method will return the enum values for the status field from the CartItem schema.

mern-marketplace/server/controllers/order.controller.js:

const getStatusValues = (req, res) => {  res.json(CartItem.schema.path('status').enumValues)}

We will also set up a fetch method in api-order.js, this is used in the view to make a request to the API route. ...

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.