Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 4 additions & 6 deletions src/helpers/overviewReportHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1471,10 +1471,10 @@ const overviewReportHelper = function () {

/**
* Aggregates total hours worked in the selected date range across all active volunteers,
* matching the dashboard's getOrgData logic exactly:
* matching the leaderboard's getLeaderboard logic:
* - Uses inclusive YYYY-MM-DD boundaries matching timeEntries.dateOfWork
* - Only active users with weeklycommittedHours >= 1 and role != Mentor
* - Excludes entryType of 'person', 'team', or 'project'
* - Includes all active users
* - Excludes inactive time entries
*/
async function getTotalHoursWorked(startDate, endDate) {
const pdtstart =
Expand All @@ -1485,8 +1485,6 @@ const overviewReportHelper = function () {
{
$match: {
isActive: true,
weeklycommittedHours: { $gte: 1 },
role: { $ne: 'Mentor' },
},
},
{
Expand All @@ -1507,7 +1505,7 @@ const overviewReportHelper = function () {
$and: [
{ $gte: ['$$timeentry.dateOfWork', pdtstart] },
{ $lte: ['$$timeentry.dateOfWork', pdtend] },
{ $not: [{ $in: ['$$timeentry.entryType', ['person', 'team', 'project']] }] },
{ $ne: ['$$timeentry.isActive', false] },
],
},
},
Expand Down
17 changes: 17 additions & 0 deletions src/helpers/overviewReportHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ describe('overviewReportHelper tests', () => {
expect(result).toEqual({ current: 11 });
},
);

it('uses the same user and time-entry inclusion rules as the leaderboard', async () => {
const aggregateSpy = jest
.spyOn(UserProfile, 'aggregate')
.mockResolvedValueOnce([{ totaltime_hrs: 12.5 }]);

const result = await overviewReportHelper().getTotalHoursWorked('2026-08-30', '2026-09-05');
const pipeline = aggregateSpy.mock.calls[0][0];

expect(pipeline[0]).toEqual({ $match: { isActive: true } });
expect(pipeline[2].$project.timeEntryData.$filter.cond.$and).toEqual([
{ $gte: ['$$timeentry.dateOfWork', '2026-08-30'] },
{ $lte: ['$$timeentry.dateOfWork', '2026-09-05'] },
{ $ne: ['$$timeentry.isActive', false] },
]);
expect(result).toEqual({ current: 12.5 });
});
});
});

Expand Down
Loading