Skip to content

Commit

Permalink
Merge pull request #672 from OneCommunityGlobal/vishala_comsumables_view
Browse files Browse the repository at this point in the history
Vishala Consumables API
  • Loading branch information
tdkent authored Jan 7, 2024
2 parents 13e5c48 + e19256d commit 7148218
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 12 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;

10 changes: 5 additions & 5 deletions src/models/bmdashboard/buildingInventoryItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const largeItemBase = mongoose.model('largeItemBase', largeItemBaseSchema, 'buil
// each document derived from this schema includes key field { __t: "material" }
// ex: sand, stone, bricks, lumber, insulation

const buildingMaterial = smallItemBase.discriminator('material', new mongoose.Schema({
const buildingMaterial = smallItemBase.discriminator('material_item', new mongoose.Schema({
stockUsed: { type: Number, default: 0 }, // stock that has been used up and cannot be reused
stockWasted: { type: Number, default: 0 }, // ruined or destroyed stock
}));
Expand All @@ -95,7 +95,7 @@ const buildingMaterial = smallItemBase.discriminator('material', new mongoose.Sc
// each document derived from this schema includes key field { __t: "consumable" }
// ex: screws, nails, staples

const buildingConsumable = smallItemBase.discriminator('consumable', new mongoose.Schema({
const buildingConsumable = smallItemBase.discriminator('consumable_item', new mongoose.Schema({
stockUsed: { type: Number, default: 0 }, // stock that has been used up and cannot be reused
stockWasted: { type: Number, default: 0 }, // ruined or destroyed stock
}));
Expand All @@ -108,7 +108,7 @@ const buildingConsumable = smallItemBase.discriminator('consumable', new mongoos
// each document derived from this schema includes key field { __t: "reusable" }
// ex: hammers, screwdrivers, mallets, brushes, gloves

const buildingReusable = smallItemBase.discriminator('reusable', new mongoose.Schema({
const buildingReusable = smallItemBase.discriminator('reusable_item', new mongoose.Schema({
stockDestroyed: { type: Number, default: 0 },
}));

Expand All @@ -120,7 +120,7 @@ const buildingReusable = smallItemBase.discriminator('reusable', new mongoose.Sc
// each document derived from this schema includes key field { __t: "tool" }
// ex: power drills, wheelbarrows, shovels, jackhammers

const buildingTool = largeItemBase.discriminator('tool', new mongoose.Schema({
const buildingTool = largeItemBase.discriminator('tool_item', new mongoose.Schema({
code: { type: Number, required: true }, // TODO: add function to create simple numeric code for on-site tool tracking
}));

Expand All @@ -134,7 +134,7 @@ const buildingTool = largeItemBase.discriminator('tool', new mongoose.Schema({
// items in this category are assumed to be rented
// ex: tractors, excavators, bulldozers

const buildingEquipment = largeItemBase.discriminator('equipment', new mongoose.Schema({
const buildingEquipment = largeItemBase.discriminator('equipment_item', new mongoose.Schema({
isTracked: { type: Boolean, required: true }, // has asset tracker
assetTracker: { type: String, required: () => this.isTracked }, // required if isTracked = true (syntax?)
}));
Expand Down
12 changes: 6 additions & 6 deletions src/models/bmdashboard/buildingInventoryType.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const invTypeBase = mongoose.model('invTypeBase', invTypeBaseSchema, 'buildingIn

// ex: sand, stone, brick, lumber

const materialType = invTypeBase.discriminator('material', new mongoose.Schema({
const materialType = invTypeBase.discriminator('material_type', new mongoose.Schema({
category: { type: String, enum: ['Material'] },
unit: { type: String, required: true }, // unit of measurement
}));
Expand All @@ -35,7 +35,7 @@ const materialType = invTypeBase.discriminator('material', new mongoose.Schema({

// ex: screws, nails, staples

const consumableType = invTypeBase.discriminator('consumable', new mongoose.Schema({
const consumableType = invTypeBase.discriminator('consumable_type', new mongoose.Schema({
category: { type: String, enum: ['Consumable'] },
size: { type: String, required: true },
}));
Expand All @@ -46,7 +46,7 @@ const consumableType = invTypeBase.discriminator('consumable', new mongoose.Sche

// ex: gloves, brushes, hammers, screwdrivers

const reusableType = invTypeBase.discriminator('reusable', new mongoose.Schema({
const reusableType = invTypeBase.discriminator('reusable_type', new mongoose.Schema({
category: { type: String, enum: ['Reusable'] },
}));

Expand All @@ -56,7 +56,7 @@ const reusableType = invTypeBase.discriminator('reusable', new mongoose.Schema({

// ex: shovels, wheelbarrows, power drills, jackhammers

const toolType = invTypeBase.discriminator('tool', new mongoose.Schema({
const toolType = invTypeBase.discriminator('tool_type', new mongoose.Schema({
category: { type: String, enum: ['Tool'] },
isPowered: { type: Boolean, required: true },
powerSource: { type: String, required: () => this.isPowered }, // required if isPowered = true (syntax?)
Expand All @@ -68,7 +68,7 @@ const toolType = invTypeBase.discriminator('tool', new mongoose.Schema({

// ex: tractors, excavators

const equipmentType = invTypeBase.discriminator('equipment', new mongoose.Schema({
const equipmentType = invTypeBase.discriminator('equipment_type', new mongoose.Schema({
category: { type: String, enum: ['Equipment'] },
fuelType: { type: String, enum: ['Diesel', 'Biodiesel', 'Gasoline', 'Natural Gas', 'Ethanol'], required: true },
}));
Expand All @@ -80,4 +80,4 @@ module.exports = {
reusableType,
toolType,
equipmentType,
};
};
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;
7 changes: 6 additions & 1 deletion src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const {
toolType,
equipmentType,
} = require('../models/bmdashboard/buildingInventoryType');
const {
buildingConsumable,
} = require('../models/bmdashboard/buildingInventoryItem');
const buildingTool = require('../models/bmdashboard/buildingTool');

const userProfileRouter = require('../routes/userProfileRouter')(userProfile);
Expand Down Expand Up @@ -74,6 +77,7 @@ const mapLocationRouter = require('../routes/mapLocationsRouter')(mapLocations);
const bmLoginRouter = require('../routes/bmdashboard/bmLoginRouter')();
const bmMaterialsRouter = require('../routes/bmdashboard/bmMaterialsRouter')(inventoryItemMaterial, buildingMaterial);
const bmProjectRouter = require('../routes/bmdashboard/bmProjectRouter')(buildingProject);
const bmConsumablesRouter = require('../routes/bmdashboard/bmConsumablesRouter')(buildingConsumable);
const bmInventoryTypeRouter = require('../routes/bmdashboard/bmInventoryTypeRouter')(invTypeBase, materialType, consumableType, reusableType, toolType, equipmentType);
const bmToolRouter = require('../routes/bmdashboard/bmToolRouter')(buildingTool);

Expand Down Expand Up @@ -113,4 +117,5 @@ module.exports = function (app) {
app.use('/api/bm', bmProjectRouter);
app.use('/api/bm', bmInventoryTypeRouter);
app.use('/api/bm', bmToolRouter);
};
app.use('/api/bm', bmConsumablesRouter);
};

0 comments on commit 7148218

Please sign in to comment.