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.84] #1023

Merged
merged 50 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
904defe
feat: separate editTimeEntry perms and add check for postTimeEntry
nathanah Apr 27, 2024
0273843
fix: corrected variable paths and ordering
nathanah May 3, 2024
f720375
Created Routing and controller function for Add Tool
pshereen May 31, 2024
b93c7ac
modified to allow non-user time entires
peter6866 Jun 6, 2024
2b9b9bd
Merge branch 'development' of https://github.com/OneCommunityGlobal/H…
cgomezhub Jun 13, 2024
2f7f780
Created Routing and Controller function for Equipment List View
pshereen Jun 15, 2024
28ee0da
feat: create getProjectByPerson route and function
nathcarnevalli Jun 18, 2024
dd9f9d4
Merge branch 'development' of https://github.com/OneCommunityGlobal/H…
cgomezhub Jun 18, 2024
acbdeda
fix: function getProjectByPerson now select projects when the user en…
nathcarnevalli Jun 21, 2024
e7a3fad
Merge branch 'development' of https://github.com/OneCommunityGlobal/H…
nathcarnevalli Jun 21, 2024
2204f2e
fix: Adjust data retrieval to use parameters instead of body
nathcarnevalli Jun 21, 2024
30051e8
Merge branch 'development' into Nathan-separate-editTimeEntry-permiss…
nathanah Jun 22, 2024
2eccbc6
Added Routing and Controller Function
pshereen Jun 26, 2024
137627f
Merge branch 'development' of https://github.com/OneCommunityGlobal/H…
cgomezhub Jun 27, 2024
91535d2
save: package-lock.json
cgomezhub Jun 27, 2024
674df72
fix: return status 400 when no projects are found
nathcarnevalli Jun 27, 2024
0a25837
fix: getProjectByPerson returns only a message when there are no proj…
nathcarnevalli Jun 27, 2024
f55fe4f
fix(validation): update teamCode regex to improve validation
Ramaruva Jun 27, 2024
fe58ca2
fix: resolve merge conflict
Ramaruva Jun 27, 2024
208c9e4
fix: resolve merge conflict
Ramaruva Jun 29, 2024
428f9f2
chore(deps): merge dependabot PRs for word-wrap and mongoose
EvianTan Jun 29, 2024
b350948
Merge pull request #1012 from OneCommunityGlobal/Yiyun-merge-dependab…
one-community Jun 29, 2024
0c4c3b3
Created Routing and controller function for fetching equipment types
pshereen Jun 30, 2024
5850ffa
Merge pull request #1014 from OneCommunityGlobal/Shereen_EquipmentPur…
one-community Jun 30, 2024
1606c5c
Merge pull request #924 from OneCommunityGlobal/Nathan-separate-editT…
one-community Jun 30, 2024
c6e5976
Merge branch 'development' into Jiayu_fix_bug_manual_add_lost_volunte…
peter6866 Jun 30, 2024
6b33b36
Merge branch 'development' of https://github.com/OneCommunityGlobal/H…
cgomezhub Jul 1, 2024
bcdd8f9
update: package.json
cgomezhub Jul 2, 2024
d8362d0
Merge branch 'development' into Carlos_NewPieChart_Hour_visualization…
cgomezhub Jul 2, 2024
82bb8f2
:q
cgomezhub Jul 2, 2024
85dfea8
update
cgomezhub Jul 2, 2024
ba6327e
clean files
cgomezhub Jul 2, 2024
fea631b
fix: delete postinstall.js
cgomezhub Jul 2, 2024
4279ea7
Add Tool Component
pshereen Jul 2, 2024
a22dd2b
chore: add style
20chen-7 Jul 3, 2024
b58c319
chore: update-symbol
20chen-7 Jul 3, 2024
d75bd7f
update package
cgomezhub Jul 4, 2024
8b02a12
Merge branch 'development' of https://github.com/OneCommunityGlobal/H…
nathcarnevalli Jul 4, 2024
7de007a
fix: query selection to properly select user's firstName and lastName
nathcarnevalli Jul 4, 2024
a4e896e
Merge pull request #977 from OneCommunityGlobal/Jiayu_fix_bug_manual_…
one-community Jul 5, 2024
e0e2be5
chore: style
20chen-7 Jul 5, 2024
9ab5b96
Merge pull request #1019 from OneCommunityGlobal/Ivy-oldHead-bq-blues…
one-community Jul 5, 2024
14918f5
Merge pull request #1015 from OneCommunityGlobal/Carlos_NewPieChart_H…
one-community Jul 6, 2024
ef6e380
blue square fringe case fix
abdel-lall Jul 6, 2024
26ee65f
Merge pull request #1006 from OneCommunityGlobal/Nathalia-new-filter-…
one-community Jul 6, 2024
600c2c0
Merge pull request #1010 from OneCommunityGlobal/Ramakrishna_Backend_…
one-community Jul 7, 2024
81c9102
Merge pull request #1022 from OneCommunityGlobal/Fix_fringe_case_blue…
one-community Jul 7, 2024
ce96b31
Merge pull request #992 from OneCommunityGlobal/Shereen_Equipment_Lis…
one-community Jul 7, 2024
931c78b
Merge pull request #970 from OneCommunityGlobal/Shereen_Add_Tool
one-community Jul 7, 2024
6dfab38
Merge pull request #1005 from OneCommunityGlobal/Shereen_Reusables_Bu…
one-community Jul 8, 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
5,722 changes: 2,788 additions & 2,934 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"eslint-import-resolver-babel-module": "^5.3.1",
"eslint-plugin-import": "^2.28.0",
"husky": "^8.0.1",
"jest": "^26.6.0",
"jest": "^29.7.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.33.1",
"eslint-plugin-react-hooks": "^4.6.0",
Expand Down Expand Up @@ -69,7 +69,7 @@
"moment": "^2.29.4",
"moment-timezone": "^0.5.35",
"mongodb": "^3.7.3",
"mongoose": "^5.13.15",
"mongoose": "^5.13.20",
"mongoose-validator": "^2.1.0",
"node-cache": "^5.1.2",
"node-datetime": "^2.0.3",
Expand All @@ -78,7 +78,7 @@
"sanitize-html": "^2.13.0",
"supertest": "^6.3.4",
"uuid": "^3.4.0",
"ws": "^8.8.1"
"ws": "^8.17.1"
},
"nodemonConfig": {
"watch": [
Expand Down
40 changes: 40 additions & 0 deletions src/controllers/bmdashboard/bmEquipmentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,45 @@ const bmEquipmentController = (BuildingEquipment) => {
}
};

const fetchBMEquipments = async (req, res) => {
try {
BuildingEquipment
.find()
.populate([
{
path: 'project',
select: '_id name',
},
{
path: 'itemType',
select: '_id name',
},
{
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);
}
};


const bmPurchaseEquipments = async function (req, res) {
const {
projectId,
Expand Down Expand Up @@ -103,6 +142,7 @@ const bmEquipmentController = (BuildingEquipment) => {
return {
fetchSingleEquipment,
bmPurchaseEquipments,
fetchBMEquipments,
};
};

Expand Down
83 changes: 83 additions & 0 deletions src/controllers/bmdashboard/bmInventoryTypeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,75 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
}
}

async function addToolType(req, res) {
const {
name,
description,
invoice,
purchaseRental,
fromDate,
toDate,
condition,
phoneNumber,
quantity,
currency,
unitPrice,
shippingFee,
taxes,
totalPriceWithShipping,
images,
link,
requestor: { requestorId },
} = req.body;

try {
ToolType.find({ name })
.then((result) => {
if (result.length) {
res.status(409).send('Oops!! Tool already exists!');
} else {
const newDoc = {
category: 'Tool',
name,
description,
invoice,
purchaseRental,
fromDate,
toDate,
condition,
phoneNumber,
quantity,
currency,
unitPrice,
shippingFee,
taxes,
totalPriceWithShipping,
images,
link,
createdBy: requestorId,
};
ToolType.create(newDoc)
.then((results) => {
res.status(201).send(results);
})
.catch((error) => {
if (error._message.includes('validation failed')) {
res.status(400).send(error.errors.unit.message);
} else {
res.status(500).send(error);
}
});
}
})
.catch((error) => {
res.status(500).send(error);
});
} catch (error) {
res.status(500).send(error);
}
}


async function fetchInventoryByType(req, res) {
const { type } = req.params;
let SelectedType = InvType;
Expand Down Expand Up @@ -272,6 +341,18 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
res.status(500).send(error);
}
}

async function fetchEquipmentTypes(req, res) {
try {
EquipType.find()
.exec()
.then((result) => res.status(200).send(result))
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
}

const fetchSingleInventoryType = async (req, res) => {
const { invtypeId } = req.params;
try {
Expand Down Expand Up @@ -317,10 +398,12 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
fetchReusableTypes,
fetchToolTypes,
addEquipmentType,
fetchEquipmentTypes,
fetchSingleInventoryType,
updateNameAndUnit,
addMaterialType,
addConsumableType,
addToolType,
fetchInvUnitsFromJson,
fetchInventoryByType,
};
Expand Down
153 changes: 149 additions & 4 deletions src/controllers/bmdashboard/bmReusableController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const {
reusableType: ReusableType,
} = require('../../models/bmdashboard/buildingInventoryType');

function isValidDate(dateString) {
const date = new Date(dateString);
return !isNaN(date.getTime());
}
// function isValidDate(dateString) {
// const date = new Date(dateString);
// return !isNaN(date.getTime());
// }

const bmReusableController = function (BuildingReusable) {
const fetchBMReusables = async (req, res) => {
Expand Down Expand Up @@ -103,9 +103,154 @@ const bmReusableController = function (BuildingReusable) {
}
};

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

if (
quantityUsed > reusable.stockAvailable ||
quantityWasted > reusable.stockAvailable ||
quantityUsed + quantityWasted > reusable.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 = +reusable.stockUsed + parseFloat(quantityUsed);
let newStockWasted = +reusable.stockWasted + parseFloat(quantityWasted);
let newAvailable =
+reusable.stockAvailable -
parseFloat(quantityUsed) -
parseFloat(quantityWasted);
newStockUsed = parseFloat(newStockUsed.toFixed(4));
newStockWasted = parseFloat(newStockWasted.toFixed(4));
newAvailable = parseFloat(newAvailable.toFixed(4));
BuildingReusable.updateOne(
{ _id: req.body.reusable._id },

{
$set: {
stockUsed: newStockUsed,
stockWasted: newStockWasted,
stockAvailable: newAvailable,
},
$push: {
updateRecord: {
date: req.body.date,
createdBy: req.body.requestor.requestorId,
quantityUsed,
quantityWasted,
},
},
}
)
.then((results) => {
res.status(200).send(results);
})
.catch((error) => res.status(500).send({ message: error }));
}
};

const bmPostReusableUpdateBulk = function (req, res) {
const reusableUpdates = req.body.upadateReusables;
let errorFlag = false;
const updateRecordsToBeAdded = [];
for (let i = 0; i < reusableUpdates.length; i+=1) {
const payload = reusableUpdates[i];
let quantityUsed = +payload.quantityUsed;
let quantityWasted = +payload.quantityWasted;
const { reusable } = payload;
if (payload.QtyUsedLogUnit === "percent" && quantityWasted >= 0) {
quantityUsed = +(
(+quantityUsed / 100) *
reusable.stockAvailable
).toFixed(4);
}
if (payload.QtyWastedLogUnit === "percent" && quantityUsed >= 0) {
quantityWasted = +(
(+quantityWasted / 100) *
reusable.stockAvailable
).toFixed(4);
}

let newStockUsed = +reusable.stockUsed + parseFloat(quantityUsed);
let newStockWasted = +reusable.stockWasted + parseFloat(quantityWasted);
let newAvailable =
+reusable.stockAvailable -
parseFloat(quantityUsed) -
parseFloat(quantityWasted);
newStockUsed = parseFloat(newStockUsed.toFixed(4));
newStockWasted = parseFloat(newStockWasted.toFixed(4));
newAvailable = parseFloat(newAvailable.toFixed(4));
if (newAvailable < 0) {
errorFlag = true;
break;
}
updateRecordsToBeAdded.push({
updateId: reusable._id,
set: {
stockUsed: newStockUsed,
stockWasted: newStockWasted,
stockAvailable: newAvailable,
},
updateValue: {
createdBy: req.body.requestor.requestorId,
quantityUsed,
quantityWasted,
date: req.body.date,
},
});
}

try {
if (errorFlag) {
res.status(500).send("Stock quantities submitted seems to be invalid");
return;
}
const updatePromises = updateRecordsToBeAdded.map((updateItem) =>
BuildingReusable.updateOne(
{ _id: updateItem.updateId },
{
$set: updateItem.set,
$push: { updateRecord: updateItem.updateValue },
}
).exec()
);
Promise.all(updatePromises)
.then((results) => {
res.status(200).send({
result: `Successfully posted log for ${results.length} Reusable records.`,
});
})
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
};




return {
fetchBMReusables,
purchaseReusable,
bmPostReusableUpdateRecord,
bmPostReusableUpdateBulk,
};
};

Expand Down
Loading
Loading