From 0888853ab93d3d122d670b72e1d59ff2ad22497f Mon Sep 17 00:00:00 2001 From: Vishala Ramasamy Date: Fri, 29 Dec 2023 17:16:45 -0800 Subject: [PATCH] Consumables first commit --- .../bmdashboard/bmConsumableController.js | 46 +++++++++++++++++++ src/routes/bmdashboard/bmConsumablesRouter.js | 13 ++++++ src/startup/routes.js | 4 ++ 3 files changed, 63 insertions(+) create mode 100644 src/controllers/bmdashboard/bmConsumableController.js create mode 100644 src/routes/bmdashboard/bmConsumablesRouter.js diff --git a/src/controllers/bmdashboard/bmConsumableController.js b/src/controllers/bmdashboard/bmConsumableController.js new file mode 100644 index 000000000..23ea6e5cd --- /dev/null +++ b/src/controllers/bmdashboard/bmConsumableController.js @@ -0,0 +1,46 @@ +const bmConsumableController = function (BuildingConsumable) { + const fetchBMConsumables = async (req, res) => { + try { + BuildingConsumable + .find() + .populate([ + { + path: 'project', + select: '_id name', + }, + { + path: 'itemType', + select: '_id name unit', + }, + { + path: 'updateRecord', + populate: { + path: 'createdBy', + select: '_id firstName lastName', + }, + }, + { + path: 'purchaseRecord', + populate: { + path: 'requestedBy', + select: '_id firstName lastName', + }, + }, + ]) + .exec() + .then(result => { + res.status(200).send(result); + }) + .catch(error => res.status(500).send(error)); + } catch (err) { + res.json(err); + } + }; + + return { + fetchBMConsumables, + }; + }; + +module.exports = bmConsumableController; + \ No newline at end of file diff --git a/src/routes/bmdashboard/bmConsumablesRouter.js b/src/routes/bmdashboard/bmConsumablesRouter.js new file mode 100644 index 000000000..51126e3a3 --- /dev/null +++ b/src/routes/bmdashboard/bmConsumablesRouter.js @@ -0,0 +1,13 @@ +const express = require('express'); + +const routes = function (BuildingConsumable) { + const BuildingConsumableController = express.Router(); + const controller = require('../../controllers/bmdashboard/bmConsumableController')(BuildingConsumable); + + BuildingConsumableController.route('/consumables') + .get(controller.fetchBMConsumables); + + return BuildingConsumableController; +}; + +module.exports = routes; diff --git a/src/startup/routes.js b/src/startup/routes.js index 620e8c9f8..963531627 100644 --- a/src/startup/routes.js +++ b/src/startup/routes.js @@ -24,6 +24,7 @@ const mapLocations = require('../models/mapLocation'); const buildingProject = require('../models/bmdashboard/buildingProject'); const buildingInventoryType = require('../models/bmdashboard/buildingInventoryType'); const buildingMaterial = require('../models/bmdashboard/buildingMaterial'); +const buildingInventoryItem = require('../models/bmdashboard/buildingInventoryItem'); const userProfileRouter = require('../routes/userProfileRouter')(userProfile); const badgeRouter = require('../routes/badgeRouter')(badge); @@ -65,6 +66,7 @@ const bmLoginRouter = require('../routes/bmdashboard/bmLoginRouter')(); const bmMaterialsRouter = require('../routes/bmdashboard/bmMaterialsRouter')(inventoryItemMaterial, buildingMaterial); const bmProjectRouter = require('../routes/bmdashboard/bmProjectRouter')(buildingProject); const bmInventoryTypeRouter = require('../routes/bmdashboard/bmInventoryTypeRouter')(buildingInventoryType); +const bmConsumablesRouter = require('../routes/bmdashboard/bmConsumablesRouter')(buildingInventoryItem.buildingConsumable); module.exports = function (app) { app.use('/api', forgotPwdRouter); @@ -101,4 +103,6 @@ module.exports = function (app) { app.use('/api/bm', bmMaterialsRouter); app.use('/api/bm', bmProjectRouter); app.use('/api/bm', bmInventoryTypeRouter); + app.use('/api/bm', bmConsumablesRouter); + };