Skip to content

Commit 6ed80c0

Browse files
Merge pull request #2096 from OneCommunityGlobal/venkataramanan_fix_team_code_reflect_from_weekly_summaries
Venkataramanan fix: quick setup team code fix
2 parents 58271c8 + a2bf76e commit 6ed80c0

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/controllers/reportsController.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,30 @@ const reportsController = function () {
730730
}
731731
};
732732

733+
const getAllDistinctTeamCodes = async (req, res) => {
734+
const requestor = safeRequestorFromReq(req);
735+
736+
try {
737+
const allowed = await hasPermission(requestor, 'getWeeklySummaries');
738+
if (!allowed) {
739+
return res.status(403).send('You are not authorized to view team codes');
740+
}
741+
742+
const teamCodes = await UserProfile.distinct('teamCode', {
743+
teamCode: { $nin: [null, ''] },
744+
});
745+
746+
const sortedTeamCodes = teamCodes.sort((a, b) => a.localeCompare(b));
747+
748+
return res.status(200).send(sortedTeamCodes);
749+
} catch (error) {
750+
console.error('Error fetching distinct team codes:', error);
751+
return res.status(500).send({
752+
error: 'An error occurred while fetching team codes.',
753+
});
754+
}
755+
};
756+
733757
const getReportTeamCodes = async (req, res) => {
734758
try {
735759
// const minActive = Number(req.query.activeMembersMinimum ?? 1);
@@ -843,6 +867,7 @@ const reportsController = function () {
843867
invalidateWeeklySummariesCache,
844868
getAdminList,
845869
sendEmailReport,
870+
getAllDistinctTeamCodes,
846871
};
847872
};
848873

src/controllers/userProfileController.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,10 +2714,8 @@ const createControllerMethods = function (UserProfile, Project, cache) {
27142714
},
27152715
},
27162716
},
2717-
userInfo: {
2718-
userId: user._id,
2719-
teamCodeWarning,
2720-
},
2717+
userId: user._id.toString(),
2718+
teamCodeWarning,
27212719
};
27222720
}),
27232721
);
@@ -2732,7 +2730,10 @@ const createControllerMethods = function (UserProfile, Project, cache) {
27322730

27332731
return res.status(200).send({
27342732
message: 'Team codes updated successfully.',
2735-
updatedUsers: updatedUsersInfo,
2733+
updatedUsers: updatedUsersInfo.map(({ userId, teamCodeWarning }) => ({
2734+
userId,
2735+
teamCodeWarning,
2736+
})),
27362737
});
27372738
} catch (error) {
27382739
console.error('Error updating team codes:', error);

src/routes/reportsRouter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const route = function () {
1414
reportsRouter.route('/reports/getrecepients').get(controller.getReportRecipients);
1515

1616
reportsRouter.route('/reports/weeklysummaries').get(controller.getWeeklySummaries);
17+
reportsRouter.get('/reports/weeklysummaries/teamcodes', controller.getAllDistinctTeamCodes);
1718

1819
reportsRouter
1920
.route('/reports/overviewsummaries/volunteerstats')

0 commit comments

Comments
 (0)