-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #567 from OneCommunityGlobal/Tim_add_materials_lis…
…t_routing Tim add materials list routing
- Loading branch information
Showing
5 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters