April 2020
Intermediate to advanced
716 pages
18h 55m
English
The possible status values of an ordered product are set as enums in the CartItem schema. 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. This API route will be declared as follows.
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. The getStatusValues controller method is defined as follows.
mern-marketplace/server/controllers/order.controller.js:
const getStatusValues = (req, res) => { res.json(CartItem.schema.path('status').enumValues)}
We will also ...