@@ -7,7 +7,11 @@ import {
77 orderBy ,
88 uniqBy ,
99} from 'lodash' ;
10- import { BadRequestException , ConflictException , Injectable } from '@nestjs/common' ;
10+ import {
11+ BadRequestException ,
12+ ConflictException ,
13+ Injectable ,
14+ } from '@nestjs/common' ;
1115import { isUUID } from 'class-validator' ;
1216import { ENV_CONFIG } from 'src/config' ;
1317import { Logger } from 'src/shared/global' ;
@@ -65,7 +69,9 @@ export class ChallengesService {
6569
6670 async getChallenge ( challengeId : string ) {
6771 if ( ! isUUID ( challengeId ) ) {
68- throw new BadRequestException ( 'Invalid challengeId provided! Uuid expected!' ) ;
72+ throw new BadRequestException (
73+ 'Invalid challengeId provided! Uuid expected!' ,
74+ ) ;
6975 }
7076
7177 const requestUrl = `${ TC_API_BASE } /challenges/${ challengeId } ` ;
@@ -142,12 +148,13 @@ export class ChallengesService {
142148
143149 return winners . map ( ( winner ) => {
144150 const currency = prizes [ winner . placement - 1 ] . type ;
145- const winType = currency === PrizeType . USD ? (
146- type ??
147- ( challenge . task . isTask
148- ? WinningsCategory . TASK_PAYMENT
149- : WinningsCategory . CONTEST_PAYMENT )
150- ) : WinningsCategory . POINTS_AWARD ;
151+ const winType =
152+ currency === PrizeType . USD
153+ ? ( type ??
154+ ( challenge . task . isTask
155+ ? WinningsCategory . TASK_PAYMENT
156+ : WinningsCategory . CONTEST_PAYMENT ) )
157+ : WinningsCategory . POINTS_AWARD ;
151158
152159 return {
153160 handle : winner . handle ,
@@ -159,7 +166,7 @@ export class ChallengesService {
159166 challenge . type === 'Task'
160167 ? challenge . name
161168 : `${ challenge . name } - ${ type === WinningsCategory . CONTEST_CHECKPOINT_PAYMENT ? 'Checkpoint ' : '' } ${ placeToOrdinal ( winner . placement ) } Place` ,
162- }
169+ } ;
163170 } ) ;
164171 }
165172
@@ -239,7 +246,9 @@ export class ChallengesService {
239246
240247 if ( placementPrizes [ 0 ] ?. type !== PrizeType . USD ) {
241248 const prizeType = placementPrizes [ 0 ] . type ;
242- this . logger . log ( `Skipping copilot payments generation for challenge ${ challenge . id } with "${ prizeType } " winning prize!` ) ;
249+ this . logger . log (
250+ `Skipping copilot payments generation for challenge ${ challenge . id } with "${ prizeType } " winning prize!` ,
251+ ) ;
243252 return [ ] ;
244253 }
245254
@@ -249,7 +258,10 @@ export class ChallengesService {
249258
250259 const copilotPrize = copilotPrizes [ 0 ] ;
251260 const currency = copilotPrize . type ;
252- const winType = currency === PrizeType . USD ? WinningsCategory . COPILOT_PAYMENT : WinningsCategory . POINTS_AWARD ;
261+ const winType =
262+ currency === PrizeType . USD
263+ ? WinningsCategory . COPILOT_PAYMENT
264+ : WinningsCategory . POINTS_AWARD ;
253265 return copilots . map ( ( copilot ) => ( {
254266 handle : copilot . memberHandle ,
255267 amount : copilotPrizes [ 0 ] . value ,
@@ -272,7 +284,9 @@ export class ChallengesService {
272284
273285 if ( placementPrizes [ 0 ] ?. type !== PrizeType . USD ) {
274286 const prizeType = placementPrizes [ 0 ] . type ;
275- this . logger . log ( `Skipping reviewers payments generation for challenge ${ challenge . id } with "${ prizeType } " winning prize!` ) ;
287+ this . logger . log (
288+ `Skipping reviewers payments generation for challenge ${ challenge . id } with "${ prizeType } " winning prize!` ,
289+ ) ;
276290 return [ ] ;
277291 }
278292
@@ -338,10 +352,12 @@ export class ChallengesService {
338352 ) ;
339353 }
340354
341-
342355 const placementPrize = placementPrizes ?. [ 0 ] ;
343356 const currency = placementPrize ?. type ;
344- const winType = currency === PrizeType . USD ? WinningsCategory . REVIEW_BOARD_PAYMENT : WinningsCategory . POINTS_AWARD ;
357+ const winType =
358+ currency === PrizeType . USD
359+ ? WinningsCategory . REVIEW_BOARD_PAYMENT
360+ : WinningsCategory . POINTS_AWARD ;
345361
346362 return {
347363 handle : reviewer . memberHandle ,
@@ -413,13 +429,17 @@ export class ChallengesService {
413429 ] ;
414430
415431 const totalUsdAmount = payments . reduce (
416- ( sum , payment ) => sum + ( payment . currency === PrizeType . USD ? payment . amount : 0 ) ,
432+ ( sum , payment ) =>
433+ sum + ( payment . currency === PrizeType . USD ? payment . amount : 0 ) ,
417434 0 ,
418435 ) ;
419436
420437 return payments . map ( ( payment ) => ( {
421438 winnerId : payment . userId . toString ( ) ,
422- type : payment . currency === PrizeType . USD ? WinningsType . PAYMENT : WinningsType . POINTS ,
439+ type :
440+ payment . currency === PrizeType . USD
441+ ? WinningsType . PAYMENT
442+ : WinningsType . POINTS ,
423443 origin : 'Topcoder' ,
424444 category : payment . type ,
425445 title : challenge . name ,
@@ -485,7 +505,10 @@ export class ChallengesService {
485505 // compute USD totals for BA validation/locking (POINT payments are persisted but not billed)
486506 const totalUsdAmount = payments . reduce (
487507 ( sum , payment ) =>
488- sum + ( payment . details [ 0 ] . currency === PrizeType . USD ? payment . details [ 0 ] . totalAmount : 0 ) ,
508+ sum +
509+ ( payment . details [ 0 ] . currency === PrizeType . USD
510+ ? payment . details [ 0 ] . totalAmount
511+ : 0 ) ,
489512 0 ,
490513 ) ;
491514
@@ -527,7 +550,9 @@ export class ChallengesService {
527550 throw new Error ( 'Challenge not found!' ) ;
528551 }
529552
530- this . logger . log ( `Challenge ${ challenge . id } - "${ challenge . name } " with status "${ challenge . status } " retrieved` ) ;
553+ this . logger . log (
554+ `Challenge ${ challenge . id } - "${ challenge . name } " with status "${ challenge . status } " retrieved` ,
555+ ) ;
531556
532557 const allowedStatuses = [
533558 ChallengeStatuses . Completed . toLowerCase ( ) ,
@@ -564,20 +589,26 @@ export class ChallengesService {
564589 }
565590
566591 try {
567- this . logger . log ( `Starting payment creation for challenge ${ challenge . id } ` ) ;
592+ this . logger . log (
593+ `Starting payment creation for challenge ${ challenge . id } ` ,
594+ ) ;
568595 await this . createPayments ( challenge , userId ) ;
569- this . logger . log ( `Payment creation completed for challenge ${ challenge . id } ` ) ;
596+ this . logger . log (
597+ `Payment creation completed for challenge ${ challenge . id } ` ,
598+ ) ;
570599 } catch ( error ) {
571600 this . logger . error (
572601 `Error while creating payments for challenge ${ challenge . id } ` ,
573602 error . message ?? error ,
574603 ) ;
575604 if (
576605 error &&
577- ( typeof error . message === 'string' ) &&
606+ typeof error . message === 'string' &&
578607 error . message . includes ( 'Lock already acquired' )
579608 ) {
580- this . logger . log ( `Conflict detected while creating payments for ${ challenge . id } ` ) ;
609+ this . logger . log (
610+ `Conflict detected while creating payments for ${ challenge . id } ` ,
611+ ) ;
581612 throw new ConflictException (
582613 'Another payment operation is in progress.' ,
583614 ) ;
0 commit comments