Orders by shop
An important feature of the marketplace is allowing sellers to see and update the status of orders they've received for products in their shops. To implement this, we will first set up APIs to list orders by shop, and then update an order as a seller changes the status of a purchased product.
List by shop API
We will implement an API to get orders for a specific shop, so authenticated sellers can view orders for each of their shops. The request for this API will be received at '/api/orders/shop/:shopId
, with the route defined in order.routes.js
as follows.
mern-marketplace/server/routes/order.routes.js
:
router.route('/api/orders/shop/:shopId') .get(authCtrl.requireSignin, shopCtrl.isOwner, orderCtrl.listByShop) router.param('shopId', shopCtrl.shopByID)
To retrieve the shop associated with the :shopId
parameter in the route, we will use the shopByID
shop controller method, which gets the shop from the Shop collection and attaches it to the request object to be accessed by the...