Skip to content

Commit

Permalink
Consumables first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishala09 committed Dec 30, 2023
1 parent 0818af5 commit 0888853
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/controllers/bmdashboard/bmConsumableController.js
Original file line number Diff line number Diff line change
@@ -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;

13 changes: 13 additions & 0 deletions src/routes/bmdashboard/bmConsumablesRouter.js
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 4 additions & 0 deletions src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

};

0 comments on commit 0888853

Please sign in to comment.