Skip to content
Merged
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
17 changes: 12 additions & 5 deletions src/controllers/titleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ const titlecontroller = function (Title) {
// Update: Confirmed with Jae. Team code is not related to the Team data model. But the team code field within the UserProfile data model.
async function checkTeamCodeExists(teamCode) {
try {
if (cache.getCache('teamCodes')) {
const teamCodes = JSON.parse(cache.getCache('teamCodes'));
return teamCodes.includes(teamCode);
const normalizedCode = (teamCode || '').trim().toUpperCase();
if (!normalizedCode) return false;

let teamCodes;

const cached = cache.getCache('teamCodes');
if (cached) {
teamCodes = JSON.parse(cached);
} else {
teamCodes = await getAllTeamCodeHelper();
}
const teamCodes = await getAllTeamCodeHelper();
return teamCodes.includes(teamCode);

return teamCodes.some((code) => (code || '').trim().toUpperCase() === normalizedCode);
} catch (error) {
console.error('Error checking if team code exists:', error);
throw error;
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,9 @@ const userProfileController = function (UserProfile, Project) {
teamCode: { $ne: null },
});

distinctTeamCodes = distinctTeamCodes.filter((code) => code && code.trim() !== '');
distinctTeamCodes = distinctTeamCodes
.map((code) => (code ? code.trim().toUpperCase() : ''))
.filter((code) => code !== '');

try {
cache.removeCache('teamCodes');
Expand Down
Loading