- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
PM-1105 - Checkpoint winners #105
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
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 | 
|---|---|---|
|  | @@ -14,7 +14,9 @@ import { | |
| Challenge, | ||
| ChallengeResource, | ||
| ChallengeReview, | ||
| Prize, | ||
| ResourceRole, | ||
| Winner, | ||
| } from './models'; | ||
| import { BillingAccountsService } from 'src/shared/topcoder/billing-accounts.service'; | ||
| import { TopcoderM2MService } from 'src/shared/topcoder/topcoder-m2m.service'; | ||
|  | @@ -117,9 +119,12 @@ export class ChallengesService { | |
| } | ||
| } | ||
|  | ||
| generateWinnersPayments(challenge: Challenge): PaymentPayload[] { | ||
| const { prizeSets, winners } = challenge; | ||
|  | ||
| generateWinnersPayments( | ||
| challenge: Challenge, | ||
| winners: Winner[], | ||
| prizes: Prize[], | ||
| type?: WinningsCategory, | ||
| ): PaymentPayload[] { | ||
| const isCancelledFailedReview = | ||
| challenge.status.toLowerCase() === | ||
| ChallengeStatuses.CancelledFailedReview.toLowerCase(); | ||
|  | @@ -128,6 +133,53 @@ export class ChallengesService { | |
| return []; | ||
| } | ||
|  | ||
| return winners.map((winner) => ({ | ||
| handle: winner.handle, | ||
| amount: prizes[winner.placement - 1].value, | ||
| userId: winner.userId.toString(), | ||
| type: | ||
| type ?? | ||
| (challenge.task.isTask | ||
| ? WinningsCategory.TASK_PAYMENT | ||
| : WinningsCategory.CONTEST_PAYMENT), | ||
| description: | ||
| challenge.type === 'Task' | ||
| ? challenge.name | ||
| : `${challenge.name} - ${placeToOrdinal(winner.placement)} Place`, | ||
| })); | ||
| } | ||
|  | ||
| generateCheckpointWinnersPayments(challenge: Challenge): PaymentPayload[] { | ||
| const { prizeSets, checkpointWinners } = challenge; | ||
|  | ||
| // generate placement payments | ||
| const checkpointPrizes = orderBy( | ||
| find(prizeSets, { type: 'CHECKPOINT' })?.prizes, | ||
| 'value', | ||
| 'desc', | ||
| ); | ||
|  | ||
| if ((checkpointPrizes?.length ?? 0) < (checkpointWinners?.length ?? 0)) { | ||
| 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. [ | ||
| throw new Error( | ||
| 'Task has incorrect number of checkpoint prizes! There are more checkpoint winners than checkpoint prizes!', | ||
| ); | ||
| } | ||
|  | ||
| if (!checkpointPrizes?.length) { | ||
| 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. [💡  | ||
| return []; | ||
| } | ||
|  | ||
| return this.generateWinnersPayments( | ||
| challenge, | ||
| checkpointWinners, | ||
| checkpointPrizes, | ||
| WinningsCategory.CONTEST_CHECKPOINT_PAYMENT, | ||
| ); | ||
| } | ||
|  | ||
| generatePlacementWinnersPayments(challenge: Challenge): PaymentPayload[] { | ||
| const { prizeSets, winners } = challenge; | ||
|  | ||
| // generate placement payments | ||
| const placementPrizes = orderBy( | ||
| find(prizeSets, { type: 'PLACEMENT' })?.prizes, | ||
|  | @@ -141,18 +193,7 @@ export class ChallengesService { | |
| ); | ||
| } | ||
|  | ||
| return winners.map((winner) => ({ | ||
| handle: winner.handle, | ||
| amount: placementPrizes[winner.placement - 1].value, | ||
| userId: winner.userId.toString(), | ||
| type: challenge.task.isTask | ||
| ? WinningsCategory.TASK_PAYMENT | ||
| : WinningsCategory.CONTEST_PAYMENT, | ||
| description: | ||
| challenge.type === 'Task' | ||
| ? challenge.name | ||
| : `${challenge.name} - ${placeToOrdinal(winner.placement)} Place`, | ||
| })); | ||
| return this.generateWinnersPayments(challenge, winners, placementPrizes); | ||
|         
                  vas3a marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| } | ||
|  | ||
| generateCopilotPayment( | ||
|  | @@ -284,7 +325,9 @@ export class ChallengesService { | |
| throw new Error('Missing challenge resources!'); | ||
| } | ||
|  | ||
| const winnersPayments = this.generateWinnersPayments(challenge); | ||
| const winnersPayments = this.generatePlacementWinnersPayments(challenge); | ||
|         
                  vas3a marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| const checkpointPayments = | ||
| this.generateCheckpointWinnersPayments(challenge); | ||
|         
                  vas3a marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| const copilotPayments = this.generateCopilotPayment( | ||
| challenge, | ||
| challengeResources.copilot, | ||
|  | @@ -315,6 +358,7 @@ export class ChallengesService { | |
|  | ||
| const payments: PaymentPayload[] = [ | ||
| ...winnersPayments, | ||
| ...checkpointPayments, | ||
| ...copilotPayments, | ||
| ...reviewersPayments, | ||
| ]; | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -36,7 +36,8 @@ export interface Challenge { | |
| created: string; | ||
| updated: string; | ||
| overview: PrizeOverview; | ||
| winners: Winner[]; // Replace with type if needed | ||
| winners: Winner[]; | ||
| checkpointWinners: Winner[]; | ||
| 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. [ | ||
| numOfSubmissions: number; | ||
| numOfCheckpointSubmissions: number; | ||
| numOfRegistrants: number; | ||
|  | ||
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.
[⚠️  
correctness]The function signature has been changed to accept
winnersandprizesas separate parameters, but the originalchallengeparameter already contains these properties. This change could lead to redundancy and potential inconsistencies if thewinnersorprizesparameters differ from those in thechallengeobject. Consider using the properties directly from thechallengeobject to maintain consistency and reduce the risk of errors.