Skip to content

Commit

Permalink
Merge pull request #694 from OneCommunityGlobal/development
Browse files Browse the repository at this point in the history
Backend Release to Main [1.31]
  • Loading branch information
one-community authored Jan 9, 2024
2 parents 4096c2c + 0d9e52a commit 0487244
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/controllers/bmdashboard/bmMaterialsController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mongoose = require('mongoose');

const bmMaterialsController = function (ItemMaterial, BuildingMaterial) {
const bmMaterialsController = function (BuildingMaterial) {
const bmMaterialsList = async function _matsList(req, res) {
try {
BuildingMaterial.find()
Expand Down Expand Up @@ -42,15 +42,9 @@ const bmMaterialsController = function (ItemMaterial, BuildingMaterial) {
matTypeId,
quantity,
priority,
brand,
brand: brandPref,
requestor: { requestorId },
} = req.body;
const newPurchaseRecord = {
quantity,
priority,
brand,
requestedBy: requestorId,
};
try {
// check if requestor has permission to make purchase request
//! Note: this code is disabled until permissions are added
Expand All @@ -64,6 +58,12 @@ const bmMaterialsController = function (ItemMaterial, BuildingMaterial) {
// check if the material is already being used in the project
// if no, add a new document to the collection
// if yes, update the existing document
const newPurchaseRecord = {
quantity,
priority,
brandPref,
requestedBy: requestorId,
};
const doc = await BuildingMaterial.findOne({ project: projectId, itemType: matTypeId });
if (!doc) {
const newDoc = {
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/bmdashboard/bmProjectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ const bmMProjectController = function (BuildingProject) {
{ $unwind: '$buildingManager' },
{
$lookup: {
from: 'buildingMaterials',
from: 'buildingInventoryItems',
let: { id: '$_id' },
pipeline: [
{ $match: { $expr: { $eq: ['$project', '$$id'] } } },
{ $match: { __t: 'material_item' } },
{ $project: { updateRecord: 0, project: 0 } },
{
$lookup: {
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ const userProfileController = function (UserProfile) {
);

const canEditTeamCode = req.body.requestor.role === 'Owner'
|| req.body.requestor.role === 'Administrator'
|| req.body.requestor.permissions?.frontPermissions.includes('editTeamCode');

if (!isRequestorAuthorized) {
Expand Down Expand Up @@ -575,6 +576,7 @@ const userProfileController = function (UserProfile) {

if (key === 'teamCode') {
const canEditTeamCode = req.body.requestor.role === 'Owner'
|| req.body.requestor.role === 'Administrator'
|| req.body.requestor.permissions?.frontPermissions.includes('editTeamCode');

if (!canEditTeamCode) {
Expand Down
4 changes: 2 additions & 2 deletions src/models/bmdashboard/buildingInventoryItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const mongoose = require('mongoose');
// documents stored in 'buildingInventoryItems' collection

const smallItemBaseSchema = mongoose.Schema({
itemType: { type: mongoose.SchemaTypes.ObjectId, ref: 'buildingInventoryType' },
itemType: { type: mongoose.SchemaTypes.ObjectId, ref: 'invTypeBase' },
project: { type: mongoose.SchemaTypes.ObjectId, ref: 'buildingProject' },
stockBought: { type: Number, default: 0 }, // total amount of item bought for use in the project
// TODO: can stockAvailable default be a function?
Expand Down Expand Up @@ -41,7 +41,7 @@ const smallItemBase = mongoose.model('smallItemBase', smallItemBaseSchema, 'buil
// documents stored in 'buildingInventoryItems' collection

const largeItemBaseSchema = mongoose.Schema({
itemType: { type: mongoose.SchemaTypes.ObjectId, ref: 'buildingInventoryType' },
itemType: { type: mongoose.SchemaTypes.ObjectId, ref: 'invTypeBase' },
project: { type: mongoose.SchemaTypes.ObjectId, ref: 'buildingProject' },
purchaseStatus: { type: String, enum: ['Rental', 'Purchase'], required: true },
// rental fields are required if purchaseStatus = "Rental" (hopefully correct syntax)
Expand Down
4 changes: 2 additions & 2 deletions src/routes/bmdashboard/bmMaterialsRouter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const express = require('express');

const routes = function (itemMaterial, buildingMaterial) {
const routes = function (buildingMaterial) {
const materialsRouter = express.Router();
const controller = require('../../controllers/bmdashboard/bmMaterialsController')(itemMaterial, buildingMaterial);
const controller = require('../../controllers/bmdashboard/bmMaterialsController')(buildingMaterial);
materialsRouter.route('/materials')
.get(controller.bmMaterialsList)
.post(controller.bmPurchaseMaterials);
Expand Down
7 changes: 4 additions & 3 deletions src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const weeklySummaryAIPrompt = require('../models/weeklySummaryAIPrompt');
const profileInitialSetuptoken = require('../models/profileInitialSetupToken');
const reason = require('../models/reason');
const mouseoverText = require('../models/mouseoverText');
const inventoryItemMaterial = require('../models/inventoryItemMaterial');
// const inventoryItemMaterial = require('../models/inventoryItemMaterial');
const mapLocations = require('../models/mapLocation');
const buildingProject = require('../models/bmdashboard/buildingProject');
const buildingMaterial = require('../models/bmdashboard/buildingMaterial');
// const buildingMaterial = require('../models/bmdashboard/buildingMaterial');
const {
invTypeBase,
materialType,
Expand All @@ -35,6 +35,7 @@ const {
} = require('../models/bmdashboard/buildingInventoryType');
const {
buildingConsumable,
buildingMaterial,
} = require('../models/bmdashboard/buildingInventoryItem');
const buildingTool = require('../models/bmdashboard/buildingTool');

Expand Down Expand Up @@ -75,7 +76,7 @@ const mapLocationRouter = require('../routes/mapLocationsRouter')(mapLocations);

// bm dashboard
const bmLoginRouter = require('../routes/bmdashboard/bmLoginRouter')();
const bmMaterialsRouter = require('../routes/bmdashboard/bmMaterialsRouter')(inventoryItemMaterial, buildingMaterial);
const bmMaterialsRouter = require('../routes/bmdashboard/bmMaterialsRouter')(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);
Expand Down

0 comments on commit 0487244

Please sign in to comment.