-
Notifications
You must be signed in to change notification settings - Fork 2
[PROD RELEASE] - Bug fixes & updates #78
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
Changes from all commits
f304ff6
6ef8e80
fed0c58
f948da0
14aff55
17d2aeb
bc313d8
90c558d
3f317af
c91a16f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,6 @@ const academyPrisma = prismaManager.getAcademyClient() | |
| const resourcesPrisma = prismaManager.getResourcesClient() | ||
| const engagementsPrisma = prismaManager.getEngagementsClient() | ||
| const profilePDFService = require('./ProfilePDFService') | ||
| const StatisticsService = require('./StatisticsService') | ||
| const request = require('request') | ||
| const cityTimezones = require('city-timezones') | ||
| const moment = require('moment-timezone') | ||
|
|
@@ -1515,11 +1514,11 @@ async function getMemberRoles (userId) { | |
| } | ||
| } | ||
|
|
||
| /** Track enum to display name (for standard tracks: wins, submissions, challenges) */ | ||
| /** Track enum to display name (wins, submissions, challenges) */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💡 |
||
| const TRACK_DISPLAY_NAMES = { | ||
| DEVELOPMENT: 'Development', | ||
| DESIGN: 'Design', | ||
| DATA_SCIENCE: 'Competitive Programming', | ||
| DATA_SCIENCE: 'Data Science', | ||
| QUALITY_ASSURANCE: 'Quality Assurance' | ||
| } | ||
|
|
||
|
|
@@ -1529,36 +1528,35 @@ const TRACK_DISPLAY_NAMES = { | |
| * @param {Number} userId member userId | ||
| * @param {Object} challengesPrisma challenges Prisma client | ||
| * @param {Object} resourcesPrisma resources Prisma client | ||
| * @returns {Promise<Array<{ trackName: string, wins: number, submissions: number, challenges: number, rating?: number, competitions?: number }>>} | ||
| * @returns {Promise<Array<{ trackName: string, wins: number, submissions: number, challenges: number }>>} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| */ | ||
| async function fetchMemberStatsByTrack (userId, challengesPrisma, resourcesPrisma) { | ||
| const trackMap = {} // track enum -> { wins, submissions, challenges } or { rating, wins, competitions } for DATA_SCIENCE | ||
| const trackMap = {} // track enum -> { wins, submissions, challenges } | ||
|
|
||
| try { | ||
| const numUserId = typeof userId === 'bigint' ? helper.bigIntToNumber(userId) : userId | ||
|
|
||
| // 1) ChallengeWinner: wins (and submissions if same table) by track | ||
| const winners = await challengesPrisma.ChallengeWinner.findMany({ | ||
| where: { userId: numUserId }, | ||
| const winnerRows = await challengesPrisma.ChallengeWinner.findMany({ | ||
| where: { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| userId: numUserId, | ||
| type: { in: ['PLACEMENT', 'PASSED_REVIEW'] } | ||
| }, | ||
| include: { | ||
| challenge: { | ||
| include: { track: true } | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| for (const w of winners) { | ||
| for (const w of winnerRows) { | ||
| const trackEnum = w.challenge?.track?.track | ||
| if (!trackEnum) continue | ||
| if (!trackMap[trackEnum]) { | ||
| const isDataScience = trackEnum === 'DATA_SCIENCE' | ||
| trackMap[trackEnum] = isDataScience | ||
| ? { wins: 0, competitions: 0, rating: undefined } | ||
| : { wins: 0, submissions: 0, challenges: 0 } | ||
| trackMap[trackEnum] = { wins: 0, submissions: 0, challenges: 0 } | ||
| } | ||
| const row = trackMap[trackEnum] | ||
| if (row.wins !== undefined) row.wins += 1 | ||
| if (row.submissions !== undefined) row.submissions += 1 | ||
| if (w.type === 'PLACEMENT') row.wins += 1 | ||
| if (w.type === 'PASSED_REVIEW') row.submissions += 1 | ||
| } | ||
|
|
||
| // 2) Resources: registrations (distinct challenges) by track | ||
|
|
@@ -1592,13 +1590,9 @@ async function fetchMemberStatsByTrack (userId, challengesPrisma, resourcesPrism | |
| } | ||
| for (const [trackEnum, count] of Object.entries(challengesPerTrack)) { | ||
| if (!trackMap[trackEnum]) { | ||
| const isDataScience = trackEnum === 'DATA_SCIENCE' | ||
| trackMap[trackEnum] = isDataScience | ||
| ? { wins: 0, competitions: count, rating: undefined } | ||
| : { wins: 0, submissions: 0, challenges: count } | ||
| trackMap[trackEnum] = { wins: 0, submissions: 0, challenges: count } | ||
| } else { | ||
| if (trackMap[trackEnum].challenges !== undefined) trackMap[trackEnum].challenges = count | ||
| if (trackMap[trackEnum].competitions !== undefined) trackMap[trackEnum].competitions = count | ||
| trackMap[trackEnum].challenges = count | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1607,22 +1601,13 @@ async function fetchMemberStatsByTrack (userId, challengesPrisma, resourcesPrism | |
| for (const [trackEnum, counts] of Object.entries(trackMap)) { | ||
| const trackName = TRACK_DISPLAY_NAMES[trackEnum] || trackEnum | ||
| const hasAny = Object.values(counts).some(v => typeof v === 'number' && v > 0) | ||
| if (!hasAny && (counts.rating == null || counts.rating === 0)) continue | ||
| if (trackEnum === 'DATA_SCIENCE') { | ||
| statsByTrack.push({ | ||
| trackName, | ||
| rating: counts.rating ?? 0, | ||
| wins: counts.wins ?? 0, | ||
| competitions: counts.competitions ?? 0 | ||
| }) | ||
| } else { | ||
| statsByTrack.push({ | ||
| trackName, | ||
| wins: counts.wins ?? 0, | ||
| submissions: counts.submissions ?? 0, | ||
| challenges: counts.challenges ?? 0 | ||
| }) | ||
| } | ||
| if (!hasAny) continue | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| statsByTrack.push({ | ||
| trackName, | ||
| wins: counts.wins ?? 0, | ||
| submissions: counts.submissions ?? 0, | ||
| challenges: counts.challenges ?? 0 | ||
| }) | ||
| } | ||
| return statsByTrack | ||
| } catch (err) { | ||
|
|
@@ -1736,28 +1721,6 @@ async function aggregatePDFData (currentUser, handle) { | |
| logger.warn(`aggregatePDFData: statsByTrack failed for ${handle}: ${err.message}`) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| } | ||
|
|
||
| // Merge Competitive Programming rating from stats endpoint (same source as GET /members/:handle/stats) | ||
| try { | ||
| const statsResult = await StatisticsService.getMemberStats(currentUser, handle, {}) | ||
| const statsResponse = Array.isArray(statsResult) && statsResult.length > 0 ? statsResult[0] : null | ||
| if (statsResponse && statsResponse.DATA_SCIENCE) { | ||
| const ds = statsResponse.DATA_SCIENCE | ||
| const rating = (ds.SRM && ds.SRM.rank && ds.SRM.rank.rating != null) | ||
| ? ds.SRM.rank.rating | ||
| : (ds.MARATHON_MATCH && ds.MARATHON_MATCH.rank && ds.MARATHON_MATCH.rank.rating != null) | ||
| ? ds.MARATHON_MATCH.rank.rating | ||
| : 0 | ||
| const cpEntry = statsByTrack.find(e => e.trackName === 'Competitive Programming') | ||
| if (cpEntry) { | ||
| cpEntry.rating = rating | ||
| } else if (rating > 0) { | ||
| statsByTrack.push({ trackName: 'Competitive Programming', rating, wins: 0, competitions: 0 }) | ||
| } | ||
| } | ||
| } catch (err) { | ||
| logger.warn(`aggregatePDFData: getMemberStats for rating failed for ${handle}: ${err.message}`) | ||
| } | ||
|
|
||
| // Fetch certifications and courses | ||
| const { certifications, courses } = await fetchCertificationsAndCourses(userId) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,6 +224,16 @@ async function getTraits (currentUser, handle, query) { | |
| if (traitIds) { | ||
| result = _.filter(result, (item) => _.includes(traitIds, item.traitId)) | ||
| } | ||
| // links in personalization are only for the profile owner (self) | ||
| if (!isSelf) { | ||
| _.forEach(result, (item) => { | ||
| if (item.traitId === 'personalization' && item.traits && item.traits.data) { | ||
| _.forEach(item.traits.data, (dataEntry) => { | ||
| delete dataEntry.links | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| }) | ||
| } | ||
| }) | ||
| } | ||
| // convert date time for traits data | ||
| _.filter(result, (item) => _.forEach(item.traits.data, function (value) { | ||
| if (value.hasOwnProperty('birthDate')) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[⚠️
maintainability]The logic for pluralizing 'wins', 'submissions', and 'challenges' is repeated. Consider extracting this logic into a helper function to improve maintainability and reduce duplication.