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
15 changes: 13 additions & 2 deletions src/apps/review/src/lib/hooks/useFetchChallengeResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import {
import { fetchChallengeReviews } from '../services'
import { ChallengeDetailContext } from '../contexts'
import { PAST_CHALLENGE_STATUSES } from '../utils/challengeStatus'
import {
SUBMISSION_TYPE_CONTEST,
} from '../constants'

type ResourceMemberMapping = ChallengeDetailContextModel['resourceMemberIdMapping']

Expand Down Expand Up @@ -135,8 +138,16 @@ const buildProjectResult = ({

// Find all submissions for this member
const memberSubmissions = submissions.filter(s => s.memberId === memberId)
const contestSubmissions = memberSubmissions.filter(
submission => (submission.type ?? SUBMISSION_TYPE_CONTEST) === SUBMISSION_TYPE_CONTEST,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The use of the nullish coalescing operator (??) here assumes that submission.type can be null or undefined. Ensure that this is the intended behavior and that submission.type is not expected to have other falsy values like an empty string.

)

// Prefer contest submissions; fall back to everything so we still display something if data is inconsistent

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ design]
The logic here prioritizes contest submissions over others. Ensure that this prioritization aligns with the business requirements and that non-contest submissions should indeed be considered only as a fallback.

const submissionsToEvaluate = contestSubmissions.length
? contestSubmissions
: memberSubmissions

if (!memberSubmissions.length) {
if (!submissionsToEvaluate.length) {
return undefined
}

Expand All @@ -148,7 +159,7 @@ const buildProjectResult = ({
computedInitialScore: number
}

const evaluated: EvaluatedSubmission[] = memberSubmissions.map(submission => {
const evaluated: EvaluatedSubmission[] = submissionsToEvaluate.map(submission => {
const fallbackReviews = submission?.reviews ?? []
const mappedReviews = reviewsBySubmissionId.get(submission.id) ?? fallbackReviews
const orderedReviews = orderReviewsByCreatedDate(mappedReviews)
Expand Down
26 changes: 17 additions & 9 deletions src/apps/review/src/lib/models/BackendChallengeInfo.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import moment from 'moment'

import { formatDurationDate } from '../utils'
import { SUBMISSION_TYPE_CONTEST } from '../constants'
import { TABLE_DATE_FORMAT } from '../../config/index.config'

import { BackendMetadata } from './BackendMetadata.model'
Expand Down Expand Up @@ -108,15 +109,22 @@ function normalizeTrack(
function mapWinners(
winners: BackendChallengeInfo['winners'],
): ChallengeWinner[] | undefined {
return winners
? winners.map(winner => ({
handle: winner.handle,
maxRating: winner.maxRating ?? undefined,
placement: winner.placement,
type: winner.type,
userId: winner.userId,
}))
: undefined
if (!winners) {
return undefined
}

// Only expose contest submissions in the winners list
const contestWinners = winners.filter(winner => (
(winner.type ?? SUBMISSION_TYPE_CONTEST) === SUBMISSION_TYPE_CONTEST

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The use of the nullish coalescing operator (??) with winner.type assumes that winner.type can be null or undefined. Ensure that this is the intended behavior and that winner.type is not expected to have other falsy values like an empty string, which would bypass the defaulting to SUBMISSION_TYPE_CONTEST.

))

return contestWinners.map(winner => ({
handle: winner.handle,
maxRating: winner.maxRating ?? undefined,
placement: winner.placement,
type: winner.type,
userId: winner.userId,
}))
}

/**
Expand Down