From 12d675f14daf4bd4880594ae2c41c80cc709b2b2 Mon Sep 17 00:00:00 2001 From: Sathishkumar Krishnan Date: Wed, 9 Feb 2022 19:22:02 +0530 Subject: [PATCH] feat: added get area, rows & bays by zone, area, row id apis --- src/controller/area.controller.js | 20 ++++++++++++++++++++ src/controller/area.router.js | 5 +++++ src/controller/row.controller.js | 20 ++++++++++++++++++++ src/controller/row.router.js | 5 +++++ src/controller/zone.controller.js | 20 ++++++++++++++++++++ src/controller/zone.router.js | 5 +++++ 6 files changed, 75 insertions(+) diff --git a/src/controller/area.controller.js b/src/controller/area.controller.js index ce0b6fd..6c671aa 100644 --- a/src/controller/area.controller.js +++ b/src/controller/area.controller.js @@ -102,4 +102,24 @@ module.exports = { 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); + } + }, }; diff --git a/src/controller/area.router.js b/src/controller/area.router.js index e4c2bdd..15a4896 100644 --- a/src/controller/area.router.js +++ b/src/controller/area.router.js @@ -11,6 +11,11 @@ router.get("/all", controller.getAllArea); */ router.get("/:id", controller.getAreaByID); +/** + * @route /area/:id/rows + */ +router.get("/:id/rows", controller.getAreaRowsByID); + /** * @route /area/ */ diff --git a/src/controller/row.controller.js b/src/controller/row.controller.js index 77f9182..11c3479 100644 --- a/src/controller/row.controller.js +++ b/src/controller/row.controller.js @@ -102,4 +102,24 @@ module.exports = { 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); + } + }, }; diff --git a/src/controller/row.router.js b/src/controller/row.router.js index fbf91be..d2593e5 100644 --- a/src/controller/row.router.js +++ b/src/controller/row.router.js @@ -12,6 +12,11 @@ router.get("/all", controller.getAllRow); */ router.get("/:id", controller.getRowByID); +/** + * @route /row/:id/bays + */ +router.get("/:id/bays", controller.getRowBaysByID); + /** * @route /row/ */ diff --git a/src/controller/zone.controller.js b/src/controller/zone.controller.js index 1625d5b..7f0d1be 100644 --- a/src/controller/zone.controller.js +++ b/src/controller/zone.controller.js @@ -102,4 +102,24 @@ module.exports = { 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); + } + }, }; diff --git a/src/controller/zone.router.js b/src/controller/zone.router.js index 3ea45f1..c0977a3 100644 --- a/src/controller/zone.router.js +++ b/src/controller/zone.router.js @@ -12,6 +12,11 @@ router.get("/all", controller.getAllZone); */ router.get("/:id", controller.getZoneByID); +/** + * @route /zone/:id/areas + */ +router.get("/:id/areas", controller.getZoneAreasByID); + /** * @route /zone/ */