Skip to content

Commit

Permalink
Merge pull request #567 from OneCommunityGlobal/Tim_add_materials_lis…
Browse files Browse the repository at this point in the history
…t_routing

Tim add materials list routing
  • Loading branch information
one-community authored Oct 19, 2023
2 parents 1df6d73 + 0038eae commit 95d787c
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 4 deletions.
48 changes: 48 additions & 0 deletions src/controllers/bmdashboard/bmMaterialsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const mongoose = require('mongoose')

const bmMaterialsController = function (ItemMaterial) {
const bmMaterialsList = async function _matsList(req, res) {
try {
ItemMaterial.find()
.populate([
{
path: 'project',
select: '_id projectName'
},
{
path: 'inventoryItemType',
select: '_id name uom totalStock totalAvailable'
},
{
path: 'usageRecord',
populate: {
path: 'createdBy',
select: '_id firstName lastName'
}
},
{
path: 'updateRecord',
populate: {
path: 'createdBy',
select: '_id firstName lastName'
}
},
{
path: 'purchaseRecord',
populate: {
path: 'createdBy',
select: '_id firstName lastName'
}
}
])
.exec()
.then(results => res.status(200).send(results))
.catch(error => res.status(500).send(error))
} catch (err) {
res.json(err);
}
};
return { bmMaterialsList };
};

module.exports = bmMaterialsController;
40 changes: 40 additions & 0 deletions src/models/inventoryItemMaterial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const mongoose = require('mongoose');

const { Schema } = mongoose;

const InventoryItemMaterial = new Schema({
inventoryItemType: { type: mongoose.SchemaTypes.ObjectId, ref: 'inventoryItemType', required: true },
project: { type: mongoose.SchemaTypes.ObjectId, ref: 'project', required: true },
stockBought: { type: Number, required: true }, // amount bought for project, affects total stock
stockUsed: { type: Number, required: true },
stockAvailable: { type: Number, required: true },
stockHeld: { type: Number, required: true },
stockWasted: { type: Number, required: true },
usageRecord: [{ // daily log of amount inventory item used at job site
date: { type: Date, required: true, default: Date.now() },
createdBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile', required: true },
quantityUsed: { type: Number, required: true },
}],
updateRecord: [{ // incident report affecting quantity/status of inventory item
date: { type: Date, required: true, default: Date.now() },
createdBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile', required: true },
action: { type: String, required: true }, // ex: Add, Reduce, Hold (updates stock quantities)
cause: { type: String, required: true }, // ex: Used, Lost, Wasted, Transfer (reason for update)
quantity: { type: Number, required: true }, // amount of material affected
description: { type: String, required: true, maxLength: 150 },
}],
purchaseRecord: [{
date: { type: Date, required: true, default: Date.now() },
createdBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile', required: true },
poId: { type: String, required: true },
sellerId: { type: String, required: true },
quantity: { type: Number, required: true }, // adds to stockBought
unitPrice: {type: Number, required: true},
currency: { type: String, required: true },
subtotal: { type: Number, required: true },
tax: { type: Number, required: true },
shipping: { type: Number, required: true },
}]
})

module.exports = mongoose.model('inventoryItemMaterial', InventoryItemMaterial, 'inventoryMaterial');
13 changes: 10 additions & 3 deletions src/models/inventoryItemType.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ const mongoose = require('mongoose');

const { Schema } = mongoose;

const InventoryItemType = new Schema({
const InventoryItemType = new Schema({ // creates an item, tracks total amount in organization's stock
type: { type: String, required: true }, // ie Material, Equipment, Tool
name: { type: String, required: true },
description: { type: String },
description: { type: String, required: true, maxLength: 150 },
uom: { type: String, required: true }, // unit of measurement
totalStock: { type: Number, required: true }, // total amount of all stock acquired
totalAvailable: { type: Number, required: true },
projectsUsing: [ {type: mongoose.SchemaTypes.ObjectId, ref: 'project'} ],
imageUrl: { type: String },
quantifier: { type: String, default: 'each' },
link: { type: String}
});

module.exports = mongoose.model('inventoryItemType', InventoryItemType, 'inventoryItemType');


13 changes: 13 additions & 0 deletions src/routes/bmdashboard/bmMaterialsRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const express = require('express');

const routes = function (itemMaterial) {
const materialsRouter = express.Router();
const controller = require('../../controllers/bmdashboard/bmMaterialsController')(itemMaterial);

materialsRouter.route('/materials')
.get(controller.bmMaterialsList);

return materialsRouter;
}

module.exports = routes;
4 changes: 3 additions & 1 deletion src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const ownerStandardMessage = require('../models/ownerStandardMessage');
const profileInitialSetuptoken = require('../models/profileInitialSetupToken');
const reason = require('../models/reason');
const mouseoverText = require('../models/mouseoverText');
const inventoryItemMaterial = require('../models/inventoryItemMaterial');

const userProfileRouter = require('../routes/userProfileRouter')(userProfile);
const badgeRouter = require('../routes/badgeRouter')(badge);
Expand Down Expand Up @@ -59,7 +60,7 @@ const mouseoverTextRouter = require('../routes/mouseoverTextRouter')(mouseoverTe

// bm dashboard
const bmLoginRouter = require('../routes/bmdashboard/bmLoginRouter')();

const bmMaterialsRouter = require('../routes/bmdashboard/bmMaterialsRouter')(inventoryItemMaterial);

module.exports = function (app) {
app.use('/api', forgotPwdRouter);
Expand Down Expand Up @@ -94,4 +95,5 @@ module.exports = function (app) {
app.use('/api', isEmailExistsRouter);
// bm dashboard
app.use('/api/bm', bmLoginRouter);
app.use('/api/bm', bmMaterialsRouter);
};

0 comments on commit 95d787c

Please sign in to comment.