feat: added widgetfamily details to inventory query & widgetfamily children get api
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const Inventory = require("../models/Inventory");
|
||||
const WidgetFamily = require("../models/WidgetFamily");
|
||||
const { InventoryTypes } = require("../config/constants");
|
||||
|
||||
module.exports = {
|
||||
@@ -162,6 +163,11 @@ module.exports = {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const inventory of inventoryData) {
|
||||
inventory["widgetFamilies"] = await WidgetFamily.find({ inventory: inventory._id });
|
||||
}
|
||||
|
||||
res.send({ success: true, data: inventoryData });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -26,6 +26,29 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the WidgetFamily children data by `id`
|
||||
*/
|
||||
getWidgetFamilyChildrenByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const widgetFamilyData = await WidgetFamily.find({ parent: id });
|
||||
if (!widgetFamilyData) {
|
||||
res.status(404).send({ success: false, error: "Widget not found" });
|
||||
return;
|
||||
}
|
||||
res.send({ success: true, data: widgetFamilyData });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a WidgetFamily
|
||||
*/
|
||||
|
||||
@@ -21,4 +21,9 @@ router.get("/search-by-inventory", controller.getWidgetFamilyByInventory);
|
||||
*/
|
||||
router.get("/:id", controller.getWidgetFamilyByID);
|
||||
|
||||
/**
|
||||
* @route /widgetFamily/:id/children
|
||||
*/
|
||||
router.get("/:id/children", controller.getWidgetFamilyChildrenByID);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user