May 2018
Intermediate to advanced
470 pages
13h 54m
English
In the backend, we will add a DELETE route that allows 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)
The remove controller method deletes the specified shop from the database, if isOwner confirms that the signed-in user is the owner of the shop.
mern-marketplace/server/controllers/shop.controller.js:
const remove = (req, res, next) => { let shop = req.shop shop.remove((err, deletedShop) => { if (err) { return res.status(400).json({ error: errorHandler.getErrorMessage(err)
}) } res.json(deletedShop) })}
Read now
Unlock full access