Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
77be65d
Code to fetch tools stoppage reason by projects or date
vamsikrishna1704 Jun 13, 2025
03addbb
Updated to the controller code of tools stoppage reason
vamsikrishna1704 Jun 14, 2025
b7036a0
Merge branch 'development' into Vamsi_Krishna_Create_a_stacked_horizo…
vamsikrishna1704 Aug 15, 2025
95439df
fix: resolved merge conflicts with the node upgrade.
vamsikrishna1704 Sep 27, 2025
14be969
feat: add tools stoppage reason API endpoints
shashankm9 Nov 13, 2025
4e76152
fix: update pagination to be applicable only when specified
ChiragBellara Apr 22, 2026
8bf1afe
fix: sonar qube error fix attempted
ChiragBellara Apr 22, 2026
7b8fbdf
fix: explicit sanitization added to fix the sonarqube error
ChiragBellara Apr 23, 2026
5455eeb
fix: updated get events to be dynamically typed
ChiragBellara Apr 23, 2026
80b53b2
fix: reduced cognitive complexity and tried another way to fix the so…
ChiragBellara Apr 23, 2026
8235298
Merge pull request #1896 from OneCommunityGlobal/fix_tools_stoppage_r…
one-community Apr 30, 2026
7bf7557
fix: update controller to include requested changes
ChiragBellara May 3, 2026
47ee6b3
fix: remove console statements and simplify auto promote logic
ChiragBellara May 3, 2026
73bdbe6
fix: updated the event controller to fix the ci cd errors
ChiragBellara May 5, 2026
a00d757
fix: revert changes back to original code to solve failing tests error
ChiragBellara May 5, 2026
21295a9
Merge branch 'development' into Vamsi_Krishna_Create_a_stacked_horizo…
aayushshetty12 May 12, 2026
202021b
fix: sonarqube duplication issue
aayushshetty12 May 12, 2026
d0153f8
chore: retrigger sonar analysis
aayushshetty12 May 12, 2026
202d242
Merge pull request #2176 from OneCommunityGlobal/chirag-fix-event-cre…
one-community May 15, 2026
1a6ffaf
fix(bs): Fixed Blue Square Issues
DiyaWadhwani May 16, 2026
844de6e
Merge pull request #2218 from OneCommunityGlobal/Diya_Fix_BSIssues
one-community May 16, 2026
ece0340
chore(deps): bump @babel/plugin-transform-modules-systemjs from 7.28.…
dependabot[bot] May 17, 2026
afb8969
chore(deps): bump axios from 1.13.2 to 1.16.1 (#2213)
dependabot[bot] May 17, 2026
500d9e0
Merge pull request #1550 from OneCommunityGlobal/Vamsi_Krishna_Create…
one-community May 17, 2026
164e904
revert: revert PR-1898
May 19, 2026
50f55b2
Merge pull request #2221 from OneCommunityGlobal/revert-1898
one-community May 19, 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
2,135 changes: 97 additions & 2,038 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test:ci": "npm test -- --coverage",
"lint": "eslint ./src --ext .js,.jsx --max-warnings=2000 --ignore-pattern '**/node_modules/**' --ignore-pattern '**/coverage/**' --ignore-pattern '**/dist/**' --ignore-pattern '**/build/**'",
"lint:fix": "eslint ./src --ext .js,.jsx --fix --ignore-pattern '**/node_modules/**' --ignore-pattern '**/coverage/**' --ignore-pattern '**/dist/**' --ignore-pattern '**/build/**'",
"build": "babel src -d dist && shx mkdir -p dist/data && shx cp -r src/data/* dist/data/",
"build": "babel src -d dist && mkdir -p dist/data && cp -r src/data/* dist/data/ 2>/dev/null || true",
"buildw": "babel src -d dist --watch",
"start": "node dist/server.js",
"dev": "nodemon --exec \"babel-node --only src src/server.js\"",
Expand Down Expand Up @@ -61,7 +61,6 @@
"pidtree": "^0.6.0",
"prettier": "3.2.5",
"puppeteer": "^24.40.0",
"shx": "^0.4.0",
"supertest": "^6.3.4"
},
"dependencies": {
Expand All @@ -83,13 +82,13 @@
"abort-controller": "^3.0.0",
"async-exit-hook": "^2.0.1",
"aws-sdk": "^2.1692.0",
"axios": "^1.7.7",
"axios": "^1.16.1",
"babel-plugin-module-resolver": "^5.0.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.4",
"card-validator": "^10.0.2",
"cheerio": "^0.22.0",
"cloudinary": "^2.9.0",
"cloudinary": "^2.8.0",
"compression": "^1.8.0",
"cors": "^2.8.4",
"cron": "^1.8.2",
Expand Down
21 changes: 12 additions & 9 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
const express = require('express');
const Sentry = require('@sentry/node');
const testRoutes = require('./routes/testRoutes');

Check warning on line 3 in src/app.js

View workflow job for this annotation

GitHub Actions / Lint Check

There should be no empty line between import groups

const app = express();
const logger = require('./startup/logger');
const globalErrorHandler = require('./utilities/errorHandling/globalErrorHandler');

Check warning on line 7 in src/app.js

View workflow job for this annotation

GitHub Actions / Lint Check

There should be no empty line between import groups
// const experienceRoutes = require('./routes/applicantAnalyticsRoutes');

// 1. Core initialization
logger.init();

app.use(Sentry.Handlers.requestHandler());

// 2. Load essential middleware (The "Engine")
// Then load all other setup
require('./startup/compression')(app);
require('./startup/cors')(app);
require('./startup/bodyParser')(app); // <--- Crucial this runs before routes
require('./startup/session')(app);
require('./startup/bodyParser')(app);
require('./startup/session')(app); // Add session before middleware and routes

// 3. Define Routes (The "Destination")
// It is better to move these INSIDE startup/routes.js, but if they stay here:
app.use('/api/test', testRoutes);

const helpFeedbackRouter = require('./routes/helpFeedbackRouter');
const helpRequestRouter = require('./routes/helpRequestRouter');

Check warning on line 23 in src/app.js

View workflow job for this annotation

GitHub Actions / Lint Check

There should be no empty line between import groups

app.use('/api/feedback', helpFeedbackRouter);
app.use('/api/helprequest', helpRequestRouter);

require('./startup/middleware')(app);
// This handles all other routes and likely has your 404 handler
require('./startup/routes')(app);

// 4. Error Handling (The "Safety Net")
const weeklyReportsRouter = require('./routes/weeklyReportsRouter');

app.use('/api', weeklyReportsRouter);

// ⚠ This must come *after* your custom /api routes
require('./startup/routes')(app);

app.use(Sentry.Handlers.errorHandler());
app.use(globalErrorHandler);

Expand Down
53 changes: 0 additions & 53 deletions src/controllers/activityLogController.js

This file was deleted.

149 changes: 149 additions & 0 deletions src/controllers/bmdashboard/bmToolStoppageReasonController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
const { ObjectId } = require('mongoose').Types;

const toolStoppageReasonController = function (ToolStoppageReason) {
const stoppageReasonFields = ['usedForLifetime', 'damaged', 'lost'];

const createPercentageProjection = (field) => ({
$cond: [
{ $gt: ['$total', 0] },
{
$round: [
{
$multiply: [{ $divide: [`$${field}`, '$total'] }, 100],
},
2,
],
},
0,
],
});

const buildProjectDateMatchStage = (projectId, startDate, endDate) => {
const matchStage = {
projectId: new ObjectId(projectId),
};

if (startDate || endDate) {
matchStage.date = {};

if (startDate) {
matchStage.date.$gte = new Date(startDate);
}

if (endDate) {
matchStage.date.$lte = new Date(endDate);
}
}

return matchStage;
};

const buildProjectIdAggregation = (collectionName, projectNameField) => [
{
$group: {
_id: '$projectId',
},
},
{
$lookup: {
from: collectionName,
localField: '_id',
foreignField: '_id',
as: 'projectDetails',
},
},
{
$project: {
_id: 1,
projectName: { $arrayElemAt: [`$projectDetails.${projectNameField}`, 0] },
},
},
{
$sort: { projectName: 1 },
},
];

const getToolsStoppageReason = async (req, res) => {
try {
const { id: projectId } = req.params;
const { startDate, endDate } = req.query;

if (!ObjectId.isValid(projectId)) {
return res.status(400).json({ error: 'Invalid project ID format' });
}

const matchStage = buildProjectDateMatchStage(projectId, startDate, endDate);

const groupSums = stoppageReasonFields.reduce(
(accumulator, field) => ({
...accumulator,
[field]: { $sum: `$${field}` },
}),
{},
);

const percentageProjection = stoppageReasonFields.reduce(
(accumulator, field) => ({
...accumulator,
[field]: createPercentageProjection(field),
}),
{},
);

const results = await ToolStoppageReason.aggregate([
{ $match: matchStage },
{
$group: {
_id: '$toolName',
...groupSums,
},
},
{
$addFields: {
total: {
$add: stoppageReasonFields.map((field) => `$${field}`),
},
},
},
{
$project: {
_id: 0,
toolName: '$_id',
...percentageProjection,
},
},
{ $sort: { toolName: 1 } },
]);

return res.json(results);
} catch (error) {
console.error('Error fetching tools stoppage reason:', error);
return res.status(500).json({ error: 'Internal server error' });
}
};

const getUniqueProjectIds = async (req, res) => {
try {
const results = await ToolStoppageReason.aggregate(
buildProjectIdAggregation('buildingProjects', 'name'),
);

const formattedResults = results.map((item) => ({
projectId: item._id,
projectName: item.projectName || 'Unknown Project',
}));

return res.json(formattedResults);
} catch (error) {
console.error('Error fetching unique project IDs:', error);
return res.status(500).json({ error: 'Internal server error' });
}
};

return {
getToolsStoppageReason,
getUniqueProjectIds,
};
};

module.exports = toolStoppageReasonController;
Loading
Loading