feat: added delete apis for warehouse, inventory, & item

This commit is contained in:
Sathishkumar Krishnan
2022-03-03 13:27:58 +05:30
parent e6e8c38765
commit 3dd0e6d8e2
6 changed files with 55 additions and 1 deletions

View File

@@ -188,4 +188,17 @@ module.exports = {
next(error);
}
},
deleteInventoryByID: async (req, res, next) => {
const { id } = req.params;
if (!id || !mongoose.isValidObjectId(id)) {
res.status(400).send({ success: false, error: "Missing/Invalid inventory id" });
}
try {
await Inventory.deleteOne({ _id: id });
res.send({ success: true, error: "Inventory Successfully deleted" });
} catch (error) {
next(error);
}
},
};

View File

@@ -37,4 +37,9 @@ router.get("/all", controller.getInventories);
*/
router.get("/:id", controller.getInventoryByID);
/**
* @route /inventory/:id
*/
router.delete("/:id", controller.deleteInventoryByID);
module.exports = router;

View File

@@ -574,4 +574,17 @@ module.exports = {
}
res.send({ success: true, data: item });
},
deleteItemByID: async (req, res, next) => {
const { id } = req.params;
if (!id || !mongoose.isValidObjectId(id)) {
res.status(400).send({ success: false, error: "Missing/Invalid item ids" });
}
try {
await Item.deleteOne({ _id: id });
res.send({ success: true, error: "Item Successfully deleted" });
} catch (error) {
next(error);
}
},
};

View File

@@ -20,10 +20,15 @@ router.post("/:id/image", upload.single("image"), controller.addImageToItem);
router.delete("/:id/image/:image_id", controller.removeImageFromItem);
/**
* @route /item/
* @route /item/:id
*/
router.patch("/:id", upload.any("images"), controller.updateItemByID);
/**
* @route /item/:id
*/
router.delete("/:id", controller.deleteItemByID);
/**
* @route /item/filter
*/

View File

@@ -199,4 +199,17 @@ module.exports = {
await warehouse.save();
res.send({ success: true, data: warehouse });
},
deleteWarehouseByID: async (req, res, next) => {
const { id } = req.params;
if (!id || !mongoose.isValidObjectId(id)) {
res.status(400).send({ success: false, error: "Missing/Invalid warehouse id" });
}
try {
await Warehouse.deleteOne({ _id: id });
res.send({ success: true, error: "Warehouse Successfully deleted" });
} catch (error) {
next(error);
}
},
};

View File

@@ -28,4 +28,9 @@ router.post("/", upload.single("image"), controller.createWarehouse);
*/
router.patch("/:id", upload.single("image"), controller.updateWarehouseByID);
/**
* @route /inventory/:id
*/
router.delete("/:id", controller.deleteWarehouseByID);
module.exports = router;