Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tim add materials list routing #567

Merged
merged 8 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -20,6 +20,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 @@ -57,7 +58,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 @@ -91,4 +92,5 @@ module.exports = function (app) {
app.use('/api', isEmailExistsRouter);
// bm dashboard
app.use('/api/bm', bmLoginRouter);
app.use('/api/bm', bmMaterialsRouter);
};
Loading