feat: added delete apis for warehouse, inventory, & item
This commit is contained in:
@@ -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);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user