feat: added widgetfamily details to inventory query & widgetfamily children get api

This commit is contained in:
Sathishkumar Krishnan
2022-01-25 15:14:50 +05:30
parent 3b8a115090
commit e04eac955e
3 changed files with 34 additions and 0 deletions

View File

@@ -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);

View File

@@ -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
*/

View File

@@ -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;