feat: added get area, rows & bays by zone, area, row id apis

This commit is contained in:
Sathishkumar Krishnan
2022-02-09 19:22:02 +05:30
parent 6657c51fd2
commit 12d675f14d
6 changed files with 75 additions and 0 deletions

View File

@@ -102,4 +102,24 @@ module.exports = {
next(error); next(error);
} }
}, },
getAreaRowsByID: async (req, res, next) => {
const { id } = req.params;
if (!id) {
res.status(400).send({ success: false, message: "Missing id param" });
return;
}
try {
const areaData = await Area.findById(id).populate("rows");
if (!areaData) {
res.status(404).send({ success: false, message: "not found" });
return;
}
res.send({ success: true, data: areaData.rows });
} catch (error) {
next(error);
}
},
}; };

View File

@@ -11,6 +11,11 @@ router.get("/all", controller.getAllArea);
*/ */
router.get("/:id", controller.getAreaByID); router.get("/:id", controller.getAreaByID);
/**
* @route /area/:id/rows
*/
router.get("/:id/rows", controller.getAreaRowsByID);
/** /**
* @route /area/ * @route /area/
*/ */

View File

@@ -102,4 +102,24 @@ module.exports = {
next(error); next(error);
} }
}, },
getRowBaysByID: async (req, res, next) => {
const { id } = req.params;
if (!id) {
res.status(400).send({ success: false, message: "Missing id param" });
return;
}
try {
const rowData = await Row.findById(id).populate("bays");
if (!rowData) {
res.status(404).send({ success: false, message: "not found" });
return;
}
res.send({ success: true, data: rowData.bays });
} catch (error) {
next(error);
}
},
}; };

View File

@@ -12,6 +12,11 @@ router.get("/all", controller.getAllRow);
*/ */
router.get("/:id", controller.getRowByID); router.get("/:id", controller.getRowByID);
/**
* @route /row/:id/bays
*/
router.get("/:id/bays", controller.getRowBaysByID);
/** /**
* @route /row/ * @route /row/
*/ */

View File

@@ -102,4 +102,24 @@ module.exports = {
next(error); next(error);
} }
}, },
getZoneAreasByID: async (req, res, next) => {
const { id } = req.params;
if (!id) {
res.status(400).send({ success: false, message: "Missing id param" });
return;
}
try {
const zoneData = await Zone.findById(id).populate("areas");
if (!zoneData) {
res.status(404).send({ success: false, message: "not found" });
return;
}
res.send({ success: true, data: zoneData.areas });
} catch (error) {
next(error);
}
},
}; };

View File

@@ -12,6 +12,11 @@ router.get("/all", controller.getAllZone);
*/ */
router.get("/:id", controller.getZoneByID); router.get("/:id", controller.getZoneByID);
/**
* @route /zone/:id/areas
*/
router.get("/:id/areas", controller.getZoneAreasByID);
/** /**
* @route /zone/ * @route /zone/
*/ */