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

Backend Release to Main [1.30] #691

Merged
merged 70 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
8036f37
Tried to fix old approach
tsunami776 Nov 1, 2023
fa3b768
Create default prompt when there is no prompt
tsunami776 Nov 9, 2023
8ee7b3b
Merge branch 'development' into Xiao-F-Create-way-for-owner-to-edit-u…
tsunami776 Nov 15, 2023
6caba89
initial commit
cvtqx Nov 16, 2023
88dea1e
merged origin/Aish_create_buildingTools_schema and updated file names
cvtqx Nov 17, 2023
14a1745
remove duplictae conroller
cvtqx Nov 20, 2023
4d4b50f
merge Aish_create_buildingTools_schema
cvtqx Nov 20, 2023
10b371e
updated buildingtool controller and schema
cvtqx Nov 20, 2023
507c61f
updated buildingtool schema and controller
cvtqx Nov 22, 2023
a49a34a
Merge branch 'development' into Xiao-F-Create-way-for-owner-to-edit-u…
tsunami776 Nov 22, 2023
403ca74
Fix model, controller and route for AI prompt
tsunami776 Nov 23, 2023
03acb2f
updates
cvtqx Nov 30, 2023
c1294d4
remake branch without package-lock.json modifications
lacnoskillz Dec 1, 2023
28badf2
changed fetchMaterialTypes back to how it was before
lacnoskillz Dec 1, 2023
be6b67f
renamed tool router and controller and fixed syntax error
cvtqx Dec 1, 2023
0a30abb
added timeOffFrom and timeOffTill fields to mongoDB
Shiwani99 Dec 6, 2023
c8b97d1
merged development
cvtqx Dec 12, 2023
18da208
updated toolcontroller query
cvtqx Dec 13, 2023
2df3865
added TimeOffFrom and TimeOffTill to dashboardhelper leaderboard pipe…
Shiwani99 Dec 17, 2023
2ecf74d
added pst time instead of est for current date
Shiwani99 Dec 17, 2023
511062f
removed current date from leaderboard aggregation pipeline
Shiwani99 Dec 17, 2023
ecc27d3
added timeOffFrom and timeOffTill to taskHelper
Shiwani99 Dec 17, 2023
7de8947
added timeOffFrom and timeOffTill to reportHelper
Shiwani99 Dec 17, 2023
33a0546
updated dashboardhelper and taskHelper to add timeOffFrom anf timeOff…
Shiwani99 Dec 18, 2023
367abce
modified the array representation for timeOffFrom and TimeOffTill to …
Shiwani99 Dec 18, 2023
676ab6d
Added comments to reasonSchedulingController.js
Shiwani99 Dec 18, 2023
5b8c91b
add equip controller, add equip func, update package-lock
tdkent Dec 21, 2023
b8996e9
add equipment router
tdkent Dec 21, 2023
08c45bb
add equipment endpoint to routes
tdkent Dec 21, 2023
d911d14
move api to invtype. delete redundant files.
tdkent Dec 21, 2023
a503971
add invtype create method
tdkent Dec 22, 2023
80d45f1
Update modifiedDatetime when team member added or removed from a team
tsunami776 Dec 22, 2023
4acbedb
add discriminators to inv type model
tdkent Dec 22, 2023
b4e0584
add inv type models to routing. update controller func for new model.
tdkent Dec 23, 2023
e812126
add validation error handling to create op
tdkent Dec 23, 2023
cdbcaf8
Merge branch 'development' into Xiao-F-update-teams-page-sorting-part-b
tsunami776 Dec 29, 2023
6953ec3
add createdBy field to base inv type model
tdkent Dec 30, 2023
0888853
Consumables first commit
Vishala09 Dec 30, 2023
e587b6a
add char limit to desc
tdkent Jan 2, 2024
b83b1b5
add duplicate name check
tdkent Jan 3, 2024
00c9387
merge w dev branch
tdkent Jan 3, 2024
037cc6f
took out the cc for review requests
beblicarl Jan 4, 2024
fcf86f5
Merge pull request #683 from OneCommunityGlobal/Carl-review-request-bug
one-community Jan 4, 2024
ce8d244
Merge branch 'development' into Xiao-F-Create-way-for-owner-to-edit-u…
tsunami776 Jan 5, 2024
27c2361
Merge pull request #684 from OneCommunityGlobal/Olga_tools_controller…
tdkent Jan 5, 2024
3003610
Merge pull request #630 from OneCommunityGlobal/kaikane-updateNameAnd…
tdkent Jan 6, 2024
cfbacf4
Merge branch 'development' into Xiao-F-update-teams-page-sorting-part-b
tsunami776 Jan 6, 2024
ae8bb2b
revert lint
tsunami776 Jan 6, 2024
33f99ab
revert changes
tsunami776 Jan 6, 2024
4923dea
fix conflicts, add base type to invtype model export
tdkent Jan 6, 2024
f939225
revert lint
tsunami776 Jan 6, 2024
7010154
Merge pull request #677 from OneCommunityGlobal/Tim_add_equip_api
tdkent Jan 6, 2024
15af5fc
Merge pull request #671 from OneCommunityGlobal/Xiao-F-update-teams-p…
one-community Jan 6, 2024
e19256d
git conflicts , type-item mongoose key name changes
Vishala09 Jan 6, 2024
13e5c48
Merge pull request #603 from OneCommunityGlobal/Xiao-F-Create-way-for…
one-community Jan 6, 2024
7148218
Merge pull request #672 from OneCommunityGlobal/vishala_comsumables_view
tdkent Jan 7, 2024
37ba941
added timeOffFrom and timeOffTill fields to new aggregation in taskHe…
Shiwani99 Jan 8, 2024
9e5f9fb
Merge branch 'shiwani_create_wayforteams_when_off_fortheweek' of http…
Shiwani99 Jan 8, 2024
65149a6
Merge branch 'development' into shiwani_create_wayforteams_when_off_f…
Shiwani99 Jan 8, 2024
b81b0a1
added timeOffFrom and timeOffTill fields to mongoDB
Shiwani99 Dec 6, 2023
02ba986
added timeOffFrom and timeOffTill to taskHelper
Shiwani99 Dec 17, 2023
c26046e
added timeOffFrom and timeOffTill to reportHelper
Shiwani99 Dec 17, 2023
a153942
updated dashboardhelper and taskHelper to add timeOffFrom anf timeOff…
Shiwani99 Dec 18, 2023
f484767
modified the array representation for timeOffFrom and TimeOffTill to …
Shiwani99 Dec 18, 2023
a956753
Added comments to reasonSchedulingController.js
Shiwani99 Dec 18, 2023
6346f4a
fixed issues with rebasing current branch with development and added …
Shiwani99 Jan 8, 2024
2913a44
resolved conflicts and rebased current branch with development
Shiwani99 Jan 8, 2024
2f36291
resolved errors after merge conflicts
Shiwani99 Jan 8, 2024
bd9a150
resolved errors in userProfile.js after conflicts
Shiwani99 Jan 8, 2024
6fc4379
Merge pull request #660 from OneCommunityGlobal/shiwani_create_wayfor…
one-community Jan 9, 2024
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
106 changes: 53 additions & 53 deletions package-lock.json

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions src/controllers/bmdashboard/bmConsumableController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const bmConsumableController = function (BuildingConsumable) {
const fetchBMConsumables = async (req, res) => {
try {
BuildingConsumable
.find()
.populate([
{
path: 'project',
select: '_id name',
},
{
path: 'itemType',
select: '_id name unit',
},
{
path: 'updateRecord',
populate: {
path: 'createdBy',
select: '_id firstName lastName',
},
},
{
path: 'purchaseRecord',
populate: {
path: 'requestedBy',
select: '_id firstName lastName',
},
},
])
.exec()
.then(result => {
res.status(200).send(result);
})
.catch(error => res.status(500).send(error));
} catch (err) {
res.json(err);
}
};

return {
fetchBMConsumables,
};
};

module.exports = bmConsumableController;

91 changes: 86 additions & 5 deletions src/controllers/bmdashboard/bmInventoryTypeController.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,100 @@
const bmInventoryTypeController = function (InvType) {
const fetchMaterialTypes = async (req, res) => {
function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolType, EquipType) {
async function fetchMaterialTypes(req, res) {
try {
InvType
MatType
.find()
.exec()
.then(result => res.status(200).send(result))
.catch(error => res.status(500).send(error));
} catch (err) {
res.json(err);
}
};
}

async function addEquipmentType(req, res) {
const {
name,
desc: description,
fuel: fuelType,
requestor: { requestorId },
} = req.body;
try {
EquipType
.find({ name })
.then((result) => {
if (result.length) {
res.status(409).send();
} else {
const newDoc = {
category: 'Equipment',
name,
description,
fuelType,
createdBy: requestorId,
};
EquipType
.create(newDoc)
.then(() => res.status(201).send())
.catch((error) => {
if (error._message.includes('validation failed')) {
res.status(400).send(error);
} else {
res.status(500).send(error);
}
});
}
})
.catch(error => res.status(500).send(error));
} catch (error) {
res.status(500).send(error);
}
}
const fetchSingleInventoryType = async (req, res) => {
const { invtypeId } = req.params;
try {
const result = await InvType.findById(invtypeId).exec();
res.status(200).send(result);
} catch (error) {
res.status(500).send(error);
}
};

const updateNameAndUnit = async (req, res) => {
try {
const { invtypeId } = req.params;
const { name, unit } = req.body;

const updateData = {};

if (name) {
updateData.name = name;
}

if (unit) {
updateData.unit = unit;
}

const updatedInvType = await InvType.findByIdAndUpdate(
invtypeId,
updateData,
{ new: true, runValidators: true },
);

if (!updatedInvType) {
return res.status(404).json({ error: 'invType Material not found check Id' });
}

res.status(200).json(updatedInvType);
} catch (error) {
res.status(500).send(error);
}
};
return {
fetchMaterialTypes,
addEquipmentType,
fetchSingleInventoryType,
updateNameAndUnit,
};
};
}

module.exports = bmInventoryTypeController;
90 changes: 40 additions & 50 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 (ItemMaterial, BuildingMaterial) {
const bmMaterialsList = async function _matsList(req, res) {
try {
BuildingMaterial.find()
Expand Down Expand Up @@ -91,25 +91,20 @@ const bmMaterialsController = function (ItemMaterial,BuildingMaterial) {
};

const bmPostMaterialUpdateRecord = function (req, res) {
let payload = req.body;
const payload = req.body;
let quantityUsed = +req.body.quantityUsed;
let quantityWasted = +req.body.quantityWasted;
let material = req.body.material;
if(payload.QtyUsedLogUnit=='percent' && quantityWasted>=0)
{
const { material } = req.body;
if (payload.QtyUsedLogUnit == 'percent' && quantityWasted >= 0) {
quantityUsed = +((+quantityUsed / 100) * material.stockAvailable).toFixed(4);
}
if(payload.QtyWastedLogUnit=='percent' && quantityUsed>=0)
{
if (payload.QtyWastedLogUnit == 'percent' && quantityUsed >= 0) {
quantityWasted = +((+quantityWasted / 100) * material.stockAvailable).toFixed(4);
}

if(quantityUsed>material.stockAvailable || quantityWasted>material.stockAvailable || (quantityUsed+quantityWasted)>material.stockAvailable)
{
res.status(500).send('Please check the used and wasted stock values. Either individual values or their sum exceeds the total stock available.')
}
else
{
if (quantityUsed > material.stockAvailable || quantityWasted > material.stockAvailable || (quantityUsed + quantityWasted) > material.stockAvailable) {
res.status(500).send('Please check the used and wasted stock values. Either individual values or their sum exceeds the total stock available.');
} else {
let newStockUsed = +material.stockUsed + parseFloat(quantityUsed);
let newStockWasted = +material.stockWasted + parseFloat(quantityWasted);
let newAvailable = +material.stockAvailable - parseFloat(quantityUsed) - parseFloat(quantityWasted);
Expand All @@ -118,45 +113,42 @@ const bmMaterialsController = function (ItemMaterial,BuildingMaterial) {
newAvailable = parseFloat(newAvailable.toFixed(4));
BuildingMaterial.updateOne(
{ _id: req.body.material._id },

{
$set: {
'stockUsed': newStockUsed,
'stockWasted': newStockWasted,
'stockAvailable': newAvailable
stockUsed: newStockUsed,
stockWasted: newStockWasted,
stockAvailable: newAvailable,
},
$push: {
updateRecord: {
date: req.body.date,
createdBy: req.body.requestor.requestorId,
quantityUsed: quantityUsed,
quantityWasted: quantityWasted
quantityUsed,
quantityWasted,
},
}
}
},
},

)
.then(results => {res.status(200).send(results)})
.catch(error => res.status(500).send({'message':error}));
.then((results) => { res.status(200).send(results); })
.catch(error => res.status(500).send({ message: error }));
}
};

const bmPostMaterialUpdateBulk = function (req, res) {
const materialUpdates= req.body.upadateMaterials;
const materialUpdates = req.body.upadateMaterials;
let errorFlag = false;
const updateRecordsToBeAdded = [];
for(let i=0;i<materialUpdates.length;i++)
{
let payload = materialUpdates[i];
for (let i = 0; i < materialUpdates.length; i++) {
const payload = materialUpdates[i];
let quantityUsed = +payload.quantityUsed;
let quantityWasted = +payload.quantityWasted;
let material = payload.material;
if(payload.QtyUsedLogUnit=='percent' && quantityWasted>=0)
{
const { material } = payload;
if (payload.QtyUsedLogUnit == 'percent' && quantityWasted >= 0) {
quantityUsed = +((+quantityUsed / 100) * material.stockAvailable).toFixed(4);
}
if(payload.QtyWastedLogUnit=='percent' && quantityUsed>=0)
{
if (payload.QtyWastedLogUnit == 'percent' && quantityUsed >= 0) {
quantityWasted = +((+quantityWasted / 100) * material.stockAvailable).toFixed(4);
}

Expand All @@ -166,38 +158,36 @@ const bmMaterialsController = function (ItemMaterial,BuildingMaterial) {
newStockUsed = parseFloat(newStockUsed.toFixed(4));
newStockWasted = parseFloat(newStockWasted.toFixed(4));
newAvailable = parseFloat(newAvailable.toFixed(4));
if(newAvailable<0)
{
if (newAvailable < 0) {
errorFlag = true;
break;
}
updateRecordsToBeAdded.push ({
updateRecordsToBeAdded.push({
updateId: material._id,
set: {
'stockUsed': newStockUsed,
'stockWasted': newStockWasted,
'stockAvailable': newAvailable
stockUsed: newStockUsed,
stockWasted: newStockWasted,
stockAvailable: newAvailable,
},
updateValue: {
createdBy: req.body.requestor.requestorId,
quantityUsed: quantityUsed,
quantityWasted: quantityWasted,
quantityUsed,
quantityWasted,
date: req.body.date,
}});
},
});
}

try {
if(errorFlag)
{
res.status(500).send('Stock quantities submitted seems to be invalid')
if (errorFlag) {
res.status(500).send('Stock quantities submitted seems to be invalid');
return;
}
const updatePromises = updateRecordsToBeAdded.map(updateItem => BuildingMaterial.updateOne(
{ _id: updateItem.updateId },
{
$set : updateItem.set,
$push: { updateRecord: updateItem.updateValue }
{
$set: updateItem.set,
$push: { updateRecord: updateItem.updateValue },
},
).exec());
Promise.all(updatePromises)
Expand All @@ -213,7 +203,7 @@ const bmMaterialsController = function (ItemMaterial,BuildingMaterial) {
bmMaterialsList,
bmPostMaterialUpdateRecord,
bmPostMaterialUpdateBulk,
bmPurchaseMaterials
bmPurchaseMaterials,
};
};

Expand Down
52 changes: 52 additions & 0 deletions src/controllers/bmdashboard/bmToolController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const bmToolController = (BuildingTool) => {
const fetchSingleTool = async (req, res) => {
const { toolId } = req.params;
try {
BuildingTool
.findById(toolId)
.populate([
{
path: 'itemType',
select: '_id name description unit imageUrl category',
},
{
path: 'userResponsible',
select: '_id firstName lastName',
},
{
path: 'purchaseRecord',
populate: {
path: 'requestedBy',
select: '_id firstName lastName',
},
},
{
path: 'updateRecord',
populate: {
path: 'createdBy',
select: '_id firstName lastName',
},
},
{
path: 'logRecord',
populate: [{
path: 'createdBy',
select: '_id firstName lastName',
},
{
path: 'responsibleUser',
select: '_id firstName lastName',
}],
},
])
.exec()
.then(tool => res.status(200).send(tool))
.catch(error => res.status(500).send(error));
} catch (err) {
res.json(err);
}
};
return { fetchSingleTool };
};

module.exports = bmToolController;
Loading
Loading