April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to delete a shop from the database, we will implement a delete shop API in the backend, which will accept a DELETE request from the client at /api/shops/:shopId. We will add the DELETE route for this API as shown in the following code, which will allow an authorized seller to delete one of their own shops:
mern-marketplace/server/routes/shop.routes.js:
router.route('/api/shops/:shopId') .delete(authCtrl.requireSignin, shopCtrl.isOwner, shopCtrl.remove)
When a DELETE request is received at this route, if the isOwner method confirms that the signed-in user is the owner of the shop, then the remove controller method deletes the shop specified by the shopId in the param. The remove method is defined as follows: