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

Abi weekly summary reports page #1062

Merged
merged 63 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
67847ce
feat: volunteer trends query
Abi-Liu Aug 10, 2024
120db4f
feat: sorted query to make it more easy to work with
Abi-Liu Aug 10, 2024
2bcfa4f
feat: fixed work distribution stats query
Abi-Liu Aug 10, 2024
7e5e21e
feat: fixed query for volunteer number stats
Abi-Liu Aug 12, 2024
1d79b47
feat: fix query for total number of hours worked
Abi-Liu Aug 14, 2024
cb4e288
feat: added comparison data for volunteer number stats
Abi-Liu Aug 23, 2024
f494165
feat: calculated growth percentage between comparison week and curren…
Abi-Liu Aug 23, 2024
6d6a93d
feat: implemented optional comparison time period and updated return …
Abi-Liu Aug 31, 2024
823dc3a
feat: added comparison logic for the get hours stats data
Abi-Liu Sep 6, 2024
a428e77
feat: added comparison data for total hours worked
Abi-Liu Sep 7, 2024
0c479b4
feat: refactored get volunteer hours stats
Abi-Liu Sep 7, 2024
1ea32f6
feat: comparison data for total active teams
Abi-Liu Sep 13, 2024
0c6a074
feat: comparison data for badges awarded
Abi-Liu Sep 13, 2024
ad8bb4d
feat: comparison data for tasks stats
Abi-Liu Sep 13, 2024
3751073
feat: added type safety, checking for null objects before accessing p…
Abi-Liu Sep 21, 2024
0591757
feat: added query to get total number of volunteers who have complete…
Abi-Liu Sep 28, 2024
90d9d63
chore: fix bug in task stats query
Abi-Liu Sep 28, 2024
0445358
Changes for Report Overview
Dk-21 Nov 2, 2024
9895bfc
feat: send data for hours-completed chart and resolve undefined varia…
strallia Oct 25, 2024
9bb0e78
fix: taskHours return value to consider null cases
strallia Oct 29, 2024
73ee181
feat: get comparison data for taskAndProjectsStats
strallia Nov 4, 2024
919a9ae
feat: use tangible hours for tasksAndProjectsStats
strallia Nov 5, 2024
3d7f4dd
feat: get data for submitted-to-committed hours percentage
strallia Nov 7, 2024
0f227d1
chore: Add documentation comments
strallia Nov 12, 2024
194cdbb
fix: return number data type for taskAndProjectStats
strallia Nov 12, 2024
9fccbad
fix: undefined variable error in getTasksStats
strallia Nov 13, 2024
eea64f8
feat: update calculateGrowthPercentage function to handle undefined c…
strallia Nov 13, 2024
67b9670
fix: undefined variable errors in getTaskAndProjectStats
strallia Nov 13, 2024
c72cc1b
feat: get total volunteers and comparison data for volunteerNumberStats
strallia Nov 17, 2024
4118ab3
refactor: simplify getVolunteerNumberStats for readability
strallia Nov 17, 2024
666160e
Changed 3 comparison function to ratio function
FayeLV Nov 18, 2024
259eb08
refactor: Simplify getVolunteerNumberStats for readability
strallia Nov 20, 2024
c18e2cd
fix: aggregation pipelines for getVolunteerNumberStats
strallia Nov 20, 2024
b1544cb
refactor: condense duplicated code in getVolunteerNumberStats
strallia Nov 20, 2024
20d412a
Nishita: Initial commit for team stats comparison feature
Nov 23, 2024
b654fc4
feat: refactoring volunteer trends query
Abi-Liu Nov 24, 2024
afe3d05
fix: revert changes to package-lock.json
strallia Nov 27, 2024
c693f0e
refactor: return only count and percentageOutOfTotal in getTeamMember…
strallia Nov 27, 2024
f12ef54
feat: add current date filters to getTeamMembersCount
strallia Nov 27, 2024
a388674
feat: add comparison date filters to getTeamMembersCount
strallia Nov 27, 2024
9e68957
chore: merge strallias pr to fix task stats query
Abi-Liu Nov 28, 2024
2aaf4b1
Merge pull request #1161 from OneCommunityGlobal/strallia-faye-volunt…
strallia Dec 4, 2024
fd4e810
Merge pull request #1158 from OneCommunityGlobal/Nishita_team_stats_c…
strallia Dec 4, 2024
9ee1dbc
feat: add route /reports/teams to get the number of teams with a mini…
strallia Dec 9, 2024
d34c902
Add getVolunteersOverAssignedTime function and integrate into getVolu…
Dk-21 Dec 12, 2024
d6bee31
refactor: update getVolunteersOverAssignedTime to use a more consiste…
strallia Dec 16, 2024
1de6562
Merge pull request #1176 from OneCommunityGlobal/add-getVolunteersOve…
strallia Dec 16, 2024
f4dde10
Add getVolunteersCompletedAssignedHours function and integrate into r…
Dk-21 Dec 14, 2024
c75f5b4
refactor: update getVolunteersCompletedAssignedHours to use a more co…
strallia Dec 16, 2024
e0cce97
Merge pull request #1177 from OneCommunityGlobal/new-volunteer-comple…
strallia Dec 16, 2024
dc5d9db
feat: update getAnniversaries to return 6 month and 1 year anniversar…
strallia Dec 17, 2024
2915280
Add comparison percentage logic to volunteer stats based on abi-volun…
Dk-21 Dec 17, 2024
67ed098
fix: undefined variable error from getTotalHoursWorked
strallia Dec 18, 2024
1a42696
Updated comments in the code for getVolunteerNumberStats function to …
Dk-21 Dec 18, 2024
fdd8881
refactor: update comment for getVolunteerNumberStats
strallia Dec 18, 2024
b19204a
Merge pull request #1184 from OneCommunityGlobal/VolunteerNumberStats…
strallia Dec 18, 2024
f6678b8
fix: timeFrame options in getVolunteerTrends
strallia Dec 30, 2024
16cabdf
fix: getVolunteerTrends to return total volunteer hours by week
strallia Jan 11, 2025
90053f4
feat: update getVolunteerTrends to get total volunteer hours by month
strallia Jan 11, 2025
4cb8996
feat: update getVolunteerTrends to use custom date parameters
strallia Jan 11, 2025
a7086d2
style: formate code
strallia Jan 11, 2025
2586d13
feat: update getAnniversaries to return user emails
strallia Jan 11, 2025
eb0f908
Merge branch 'origin/development' into abi-volunteer-trends
strallia Jan 11, 2025
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
156 changes: 146 additions & 10 deletions src/controllers/reportsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,42 @@ const UserProfile = require('../models/userProfile');
const reportsController = function () {
const overviewReportHelper = overviewReportHelperClosure();
const reporthelper = reporthelperClosure();

/**
* Aggregates the trend data for volunteer count
* Parameters:
* timeFrame - 0, 1, 2, etc: 0 represents all time
* offset - *STRING* week/month
* customStartDate / customEndDate - *DATE STRING as "YYYY-MM-DD" || NULL* custom date ranges, overrides timeFrame parameter
*/
const getVolunteerTrends = async (req, res) => {
const { timeFrame, offset, customStartDate, customEndDate } = req.query;

if (!timeFrame || !offset) {
return res.status(400).send({ msg: 'Please provide a timeframe and offset' });
}

if (![0, 1, 2, 3, 5, 10].includes(+timeFrame)) {
return res.status(400).send({ msg: 'Invalid timeFrame' });
}

if (!['week', 'month'].includes(offset)) {
return res.status(400).send({ msg: 'Offset param must either be `week` or `month`' });
}

try {
const data = await overviewReportHelper.getVolunteerTrends(
timeFrame,
offset,
customStartDate,
customEndDate,
);
res.status(200).send(data);
} catch (err) {
res.status(400).send(err);
}
};

/**
* Aggregates all the data needed for the volunteer stats page
* # Active volunteers
Expand All @@ -20,10 +56,20 @@ const reportsController = function () {
* In teams stats
*/
const getVolunteerStatsData = async (req, res) => {
const { startDate, endDate } = req.query;
const { startDate, endDate, comparisonStartDate, comparisonEndDate } = req.query;

if (!startDate || !endDate) {
return res.status(400).send({ msg: 'Please provide a start and end date' });
}

let isoComparisonStartDate;
let isoComparisonEndDate;

if (comparisonStartDate && comparisonEndDate) {
isoComparisonStartDate = new Date(comparisonStartDate);
isoComparisonEndDate = new Date(comparisonEndDate);
}

const isoStartDate = new Date(startDate);
const isoEndDate = new Date(endDate);

Expand All @@ -41,19 +87,77 @@ const reportsController = function () {
totalBadgesAwarded,
totalActiveTeams,
userLocations,
completedHours,
taskAndProjectStats,
volunteersOverAssignedTime,
completedAssignedHours,
] = await Promise.all([
overviewReportHelper.getVolunteerNumberStats(isoStartDate, isoEndDate),
overviewReportHelper.getHoursStats(isoStartDate, isoEndDate),
overviewReportHelper.getTotalHoursWorked(isoStartDate, isoEndDate),
overviewReportHelper.getTasksStats(isoStartDate, isoEndDate),
overviewReportHelper.getWorkDistributionStats(isoStartDate, isoEndDate),
overviewReportHelper.getVolunteerNumberStats(
isoStartDate,
isoEndDate,
isoComparisonStartDate,
isoComparisonEndDate,
),
overviewReportHelper.getHoursStats(
isoStartDate,
isoEndDate,
isoComparisonStartDate,
isoComparisonEndDate,
),
overviewReportHelper.getTotalHoursWorked(
isoStartDate,
isoEndDate,
isoComparisonStartDate,
isoComparisonEndDate,
),
overviewReportHelper.getTasksStats(
isoStartDate,
isoEndDate,
isoComparisonStartDate,
isoComparisonEndDate,
),
overviewReportHelper.getWorkDistributionStats(
isoStartDate,
isoEndDate,
isoComparisonStartDate,
isoComparisonEndDate,
),
overviewReportHelper.getRoleDistributionStats(),
overviewReportHelper.getTeamMembersCount(),
overviewReportHelper.getTeamMembersCount(isoEndDate, isoComparisonEndDate),
// overviewReportHelper.getBlueSquareStats(startDate, endDate),
overviewReportHelper.getAnniversaries(startDate, endDate),
overviewReportHelper.getTotalBadgesAwardedCount(startDate, endDate),
overviewReportHelper.getTotalActiveTeamCount(),
overviewReportHelper.getAnniversaries(
isoStartDate,
isoEndDate,
isoComparisonStartDate,
isoComparisonEndDate,
),
overviewReportHelper.getTotalBadgesAwardedCount(
startDate,
endDate,
isoComparisonStartDate,
isoComparisonEndDate,
),
overviewReportHelper.getTotalActiveTeamCount(isoEndDate, isoComparisonEndDate),
overviewReportHelper.getMapLocations(),
overviewReportHelper.getVolunteersCompletedHours(
isoStartDate,
isoEndDate,
isoComparisonStartDate,
isoComparisonEndDate,
),
overviewReportHelper.getTaskAndProjectStats(
startDate,
endDate,
comparisonStartDate,
comparisonEndDate,
),
overviewReportHelper.getVolunteersOverAssignedTime(isoStartDate, isoEndDate),
overviewReportHelper.getVolunteersCompletedAssignedHours(
isoStartDate,
isoEndDate,
isoComparisonStartDate,
isoComparisonEndDate,
),
]);
res.status(200).send({
volunteerNumberStats,
Expand All @@ -68,6 +172,10 @@ const reportsController = function () {
totalBadgesAwarded,
totalActiveTeams,
userLocations,
completedHours,
taskAndProjectStats,
volunteersOverAssignedTime,
completedAssignedHours,
});
} catch (err) {
console.log(err);
Expand Down Expand Up @@ -393,6 +501,32 @@ const reportsController = function () {
}
};

const getTeamsWithActiveMembers = async (req, res) => {
const { endDate, activeMembersMinimum } = req.query;

if (!endDate) {
return res.status(400).send({ msg: 'Please provide an end date' });
}
if (!activeMembersMinimum) {
return res.status(400).send({
msg: 'Please provide the number of minimum active members in the team (activeMembersMinimum query param)',
});
}

const isoEndDate = new Date(endDate);

try {
const teamsWithActiveMembers = await overviewReportHelper.getTeamsWithActiveMembers(
isoEndDate,
Number(activeMembersMinimum),
);
res.status(200).send({ teamsWithActiveMembers });
} catch (err) {
console.log(err);
res.status(500).send({ msg: 'Error occured while fetching data. Please try again!' });
}
};

return {
getVolunteerStats,
getVolunteerHoursStats,
Expand All @@ -404,6 +538,8 @@ const reportsController = function () {
getVolunteerRoleStats,
getBlueSquareStats,
getVolunteerStatsData,
getVolunteerTrends,
getTeamsWithActiveMembers,
};
};

Expand Down
Loading
Loading