-
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 #577 from OneCommunityGlobal/gary_add_materials_page
Gary add materials page
- Loading branch information
Showing
11 changed files
with
211 additions
and
71 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,19 @@ | ||
const bmInventoryTypeController = function (InvType) { | ||
const fetchMaterialTypes = async (req, res) => { | ||
try { | ||
InvType | ||
.find() | ||
.exec() | ||
.then(result => res.status(200).send(result)) | ||
.catch(error => res.status(500).send(error)); | ||
} catch (err) { | ||
res.json(err); | ||
} | ||
}; | ||
|
||
return { | ||
fetchMaterialTypes, | ||
}; | ||
}; | ||
|
||
module.exports = bmInventoryTypeController; |
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
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 mongoose = require('mongoose'); | ||
|
||
const { Schema } = mongoose; | ||
|
||
const buildingInventoryType = new Schema({ | ||
category: { type: String, enum: ['Consumable', 'Material', 'Tool', 'Equipment'], required: true }, | ||
name: { type: String, required: true }, | ||
description: { type: String, required: true }, | ||
unit: { type: String, required: true }, // unit of measurement | ||
imageUrl: String, | ||
}); | ||
|
||
module.exports = mongoose.model('buildingInventoryType', buildingInventoryType, 'buildingInventoryTypes'); |
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,30 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const { Schema } = mongoose; | ||
|
||
const buildingMaterial = new Schema({ | ||
itemType: { type: mongoose.SchemaTypes.ObjectId, ref: 'buildingInventoryType' }, | ||
project: { type: mongoose.SchemaTypes.ObjectId, ref: 'buildingProject' }, | ||
stockBought: { type: Number, default: 0 }, // total amount of item bought for use in the project | ||
stockUsed: { type: Number, default: 0 }, // total amount of item used successfully in the project | ||
stockWasted: { type: Number, default: 0 }, // total amount of item wasted/ruined/lost in the project | ||
stockAvailable: { type: Number, default: 0 }, // bought - (used + wasted) | ||
purchaseRecord: [{ | ||
_id: false, // do not add _id field to subdocument | ||
date: { type: Date, default: Date.now() }, | ||
requestedBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' }, | ||
quantity: { type: Number, required: true }, | ||
priority: { type: String, enum: ['Low', 'Medium', 'High'], required: true }, | ||
brand: String, | ||
status: { type: String, default: 'Pending', enum: ['Approved', 'Pending', 'Rejected'] }, | ||
}], | ||
updateRecord: [{ | ||
_id: false, | ||
date: { type: Date, required: true }, | ||
createdBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' }, | ||
quantityUsed: { type: Number, required: true }, | ||
quantityWasted: { type: Number, required: true }, | ||
}], | ||
}); | ||
|
||
module.exports = mongoose.model('buildingMaterial', buildingMaterial, 'buildingMaterials'); |
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
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 (invType) { | ||
const inventoryTypeRouter = express.Router(); | ||
const controller = require('../../controllers/bmdashboard/bmInventoryTypeController')(invType); | ||
|
||
inventoryTypeRouter.route('/invtypes/materials') | ||
.get(controller.fetchMaterialTypes); | ||
|
||
return inventoryTypeRouter; | ||
}; | ||
|
||
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
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