Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4102c73
feat(api): added controllers, models and api endpoints
aayushshetty12 Oct 12, 2025
8d4ed6b
feat: added additional models required
aayushshetty12 Oct 17, 2025
14ba324
feat: implemented 3 task comment apis
aayushshetty12 Oct 25, 2025
58338d4
feat: fixed isDeleted flag issue
aayushshetty12 Oct 25, 2025
f9888d8
feat: Created an analytics api for fetching job hits, applications an…
harshavarma29 Nov 4, 2025
ae442dd
feat: initial commit
adithya-6101 Jan 7, 2026
6c75c8f
fix: resolve merge conflict
aayushshetty12 Jan 11, 2026
e6cf2e1
Merge branch 'development' of https://github.com/OneCommunityGlobal/H…
aayushshetty12 Jan 13, 2026
b21f80e
feat: Backend fix for updating tools
adithya-6101 Jan 21, 2026
e0ebb86
feat: add fix for failing cicd tests
adithya-6101 Jan 22, 2026
adffe38
feat: Swathi_Backend implementation for Edit and View history
SwathiAngadi Jan 23, 2026
5c0c600
feat: Made functionality to handle generic scenarios
SwathiAngadi Feb 5, 2026
1903035
REsolved merge conflicts
SwathiAngadi Mar 2, 2026
6acb964
fix:REsolved merge conflicts
SwathiAngadi Mar 2, 2026
bec6602
fix: Removed test case
SwathiAngadi Mar 3, 2026
fdf1697
fix: sonar security issue
SwathiAngadi Mar 3, 2026
4ab7317
fix: Secuirty issue fixed
SwathiAngadi Mar 3, 2026
d72d8bc
fix: sonar cube security issue
SwathiAngadi Mar 4, 2026
87b87d4
fix: sonar cube security issue
SwathiAngadi Mar 4, 2026
874ffaf
fix: sonar qube security issue
SwathiAngadi Mar 4, 2026
1f3c811
fix: sonar qube security issue
SwathiAngadi Mar 4, 2026
d5f6f3b
fix: personal max badge and resolve all associated bugs
sohailuddinsyed Mar 22, 2026
00f525c
fix: use lean() and guard internal keys in community skill filter
sohailuddinsyed Mar 29, 2026
21798c7
fix: sanitize user input and add lean() to fix community skill filter
sohailuddinsyed Mar 29, 2026
a92fbe6
fix(api): fixed null summary value
aayushshetty12 Apr 2, 2026
f12bac7
Merge branch 'development' into aayush_summary_null_fix
aayushshetty12 Apr 2, 2026
bad0e46
fix: merge conflicts resolved
aayushshetty12 Apr 6, 2026
f415c66
fix: resolved merge conflicts
aayushshetty12 Apr 6, 2026
617e225
Remove console log in getStudentCommentsbyStudent
aayushshetty12 Apr 6, 2026
7fd2884
fix: fixed the merge conflicts with the development branch
harshavarma29 Apr 7, 2026
ffa10d9
feat: reEsolved merge conflict
SwathiAngadi Apr 8, 2026
9eef8c0
Revert "feat: reEsolved merge conflict"
SwathiAngadi Apr 8, 2026
51ba781
fix: Code lost in merge
SwathiAngadi Apr 8, 2026
7416041
fix: Checking for failed test case
SwathiAngadi Apr 9, 2026
50b8e43
Revert "Revert "feat: reEsolved merge conflict""
SwathiAngadi Apr 9, 2026
c21d374
Merge pull request #2116 from OneCommunityGlobal/Sohail-fix-personal-…
one-community Apr 9, 2026
84a9088
Merge pull request #2014 from OneCommunityGlobal/Swathi-API_EditInfo_…
one-community Apr 9, 2026
9a33475
Merge pull request #1882 from OneCommunityGlobal/harsha_job_hits_and_…
one-community Apr 9, 2026
f2d4936
Merge pull request #1992 from OneCommunityGlobal/adithya_fix_tool_upd…
one-community Apr 9, 2026
77c7423
Merge pull request #2143 from OneCommunityGlobal/Sohail-community-mem…
one-community Apr 10, 2026
015aac1
chore: fix sonar test issue
Apr 11, 2026
f9a33ff
Merge pull request #2163 from OneCommunityGlobal/sundar/fix-sonar-test
one-community Apr 11, 2026
502ea09
Refactor user validation and comment handling
aayushshetty12 Apr 12, 2026
e2dc777
fix: sonarqube issue
aayushshetty12 Apr 12, 2026
bb05d27
fix: merge conflicts
aayushshetty12 Apr 12, 2026
d61d454
Merge pull request #2146 from OneCommunityGlobal/aayush_summary_null_fix
one-community Apr 12, 2026
3b9cab0
Merge pull request #1857 from OneCommunityGlobal/aayush-task-level-co…
one-community Apr 12, 2026
2791f38
chore: fix app run issue on dev
Apr 13, 2026
61eff0c
Merge pull request #2165 from OneCommunityGlobal/sundar/fix-app-run
one-community Apr 13, 2026
b60695e
fix(wsEmail): Weekly Summary Email Users
DiyaWadhwani Apr 15, 2026
8b09961
Merge pull request #2168 from OneCommunityGlobal/Diya_Fix_WeeklySumma…
one-community Apr 15, 2026
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
16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@
"/src/**/*"
]
}
}
}
12 changes: 6 additions & 6 deletions src/controllers/badgeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const UserProfile = require('../models/userProfile');
const helper = require('../utilities/permissions');
const escapeRegex = require('../utilities/escapeRegex');
const cacheClosure = require('../utilities/nodeCache');
// const userHelper = require('../helpers/userHelper')();
const userHelper = require('../helpers/userHelper')();

const badgeController = function (Badge) {
/**
Expand All @@ -13,10 +13,10 @@ const badgeController = function (Badge) {
*/
const cache = cacheClosure();

// const awardBadgesTest = async function (req, res) {
// await userHelper.awardNewBadges();
// res.status(200).send('Badges awarded');
// };
const awardNewBadges = async function (req, res) {
await userHelper.awardNewBadges();
res.status(200).send('Badges awarded');
};

const getAllBadges = async function (req, res) {
// console.log(req.body.requestor); // Retain logging from development branch for debugging
Expand Down Expand Up @@ -341,7 +341,7 @@ const badgeController = function (Badge) {
};

return {
// awardBadgesTest,
awardNewBadges,
getAllBadges,
assignBadges,
postBadge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const mockEquipType = {
exec: jest.fn(),
};

const mockInvTypeHistory = {
find: jest.fn(),
create: jest.fn(),
exec: jest.fn(),
};
const mockInvType = {
find: jest.fn(),
findById: jest.fn(),
Expand Down Expand Up @@ -64,6 +69,7 @@ describe('Building Materials Inventory Controller', () => {
mockReusType,
mockToolType,
mockEquipType,
mockInvTypeHistory,
);

req = {
Expand Down Expand Up @@ -173,36 +179,4 @@ describe('Building Materials Inventory Controller', () => {
expect(res.send).toHaveBeenCalledWith(mockTools);
});
});

describe('updateNameAndUnit', () => {
it('should update name and unit successfully', async () => {
req.params = { invtypeId: 'inv123' };
req.body = { name: 'Updated Name', unit: 'Updated Unit' };

const updatedDoc = { ...req.body, _id: 'inv123' };
mockInvType.findByIdAndUpdate.mockResolvedValue(updatedDoc);

await controller.updateNameAndUnit(req, res);

expect(mockInvType.findByIdAndUpdate).toHaveBeenCalledWith(
'inv123',
{ name: 'Updated Name', unit: 'Updated Unit' },
{ new: true, runValidators: true },
);
expect(res.status).toHaveBeenCalledWith(200);
expect(res.json).toHaveBeenCalledWith(updatedDoc);
});

it('should handle non-existent inventory type', async () => {
req.params = { invtypeId: 'nonexistent' };
req.body = { name: 'Updated Name' };

mockInvType.findByIdAndUpdate.mockResolvedValue(null);

await controller.updateNameAndUnit(req, res);

expect(res.status).toHaveBeenCalledWith(404);
expect(res.json).toHaveBeenCalledWith({ error: 'invType Material not found check Id' });
});
});
});
130 changes: 118 additions & 12 deletions src/controllers/bmdashboard/bmInventoryTypeController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const fsPromises = require('fs/promises');
const path = require('path');
const mongoose = require('mongoose');

const filename = 'BuildingUnits.json';
const currentFilePath = __filename;
Expand All @@ -9,7 +10,15 @@ const filepath = path.join(rootPath, filename);
const { readFile } = fs;
const { writeFile } = fs;

function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolType, EquipType) {
function bmInventoryTypeController(
InvType,
MatType,
ConsType,
ReusType,
ToolType,
EquipType,
invTypeHistory,
) {
async function fetchMaterialTypes(req, res) {
try {
MatType.find()
Expand Down Expand Up @@ -398,22 +407,98 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
};

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

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

if (!updatedInvType) {
return res.status(404).json({ error: 'invType Material not found check Id' });
const { invtypeId } = req.params;
const {
name,
unit,
type: rawType,
requestor: { requestorId },
} = req.body;
const historyDocs = [];
const updateData = {};
// Selection of Collection depending on Type
const allowedTypes = ['Material', 'Consumable'];
const itemTtype = allowedTypes.includes(rawType) ? rawType : 'Inventory';

// Validate invtypeId
if (!mongoose.Types.ObjectId.isValid(invtypeId)) {
return res.status(400).json({ message: 'Invalid inventory type ID' });
}
// Sanitize name
const safeName = String(name).trim();
if (!safeName) {
return res.status(400).json({ message: 'Invalid inventory name' });
}
// Extract and sanitize
const safeUnit = String(unit).trim();
if (!safeUnit || safeUnit.length > 50) {
return res.status(400).json({ message: 'Invalid unit value' });
}

let CollectionName = InvType;
if (itemTtype === 'Material') {
CollectionName = MatType;
} else if (itemTtype === 'Consumable') {
CollectionName = ConsType;
}

// Fetch existing document
const invType = await CollectionName.findById(invtypeId);
if (!invType) {
return res.status(404).send('Inventory type not found check Id');
}

// Perform query using sanitized values
const existingInvType = await CollectionName.findOne({
name: safeName,
_id: { $ne: mongoose.Types.ObjectId(invtypeId) },
});

if (existingInvType) {
return res.status(409).json({
message: 'Inventory type name already exists',
});
}

// Track name change
if (safeName && safeName !== invType.name) {
historyDocs.push({
invtypeId,
field: 'name',
oldValue: invType.name,
newValue: safeName,
editedBy: requestorId,
});
updateData.name = safeName;
}

// Track unit change
if (safeUnit && safeUnit !== invType.unit) {
historyDocs.push({
invtypeId,
field: 'unit',
oldValue: invType.unit,
newValue: safeUnit,
editedBy: requestorId,
});
updateData.unit = safeUnit;
}

// Save history (if any)
if (historyDocs.length > 0) {
await invTypeHistory.insertMany(historyDocs);
}

// Update main document
const updatedInvType = await CollectionName.findByIdAndUpdate(invtypeId, updateData, {
new: true,
runValidators: true,
});

res.status(200).json(updatedInvType);
} catch (error) {
console.error(error);
res.status(500).send(error);
}
};
Expand Down Expand Up @@ -638,6 +723,26 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
}
};

const fetchInvTypeHistory = async (req, res) => {
try {
const { invtypeId } = req.params;
const safeInvTypeId = new mongoose.Types.ObjectId(invtypeId);
if (!mongoose.Types.ObjectId.isValid(invtypeId)) {
return res.status(400).json({ message: 'Invalid inventory type id' });
}

const history = await invTypeHistory
.find({ invtypeId: safeInvTypeId })
.populate('editedBy', '_id firstName lastName email')
.sort({ editedAt: -1 })
.lean();

res.status(200).json(history);
} catch (error) {
console.error('Fetch history error:', error);
res.status(500).json({ message: 'Failed to fetch inventory history' });
}
};
return {
fetchMaterialTypes,
fetchConsumableTypes,
Expand All @@ -657,6 +762,7 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
deleteInvUnit,
updateSingleInvType,
deleteSingleInvType,
fetchInvTypeHistory,
};
}

Expand Down
Loading
Loading