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. ...