Skip to content

Commit b339c49

Browse files
authored
Merge pull request #164 from topcoder-platform/dev
Prod deploy for engagements updates
2 parents fd8169f + ff6d801 commit b339c49

12 files changed

Lines changed: 1756 additions & 40 deletions

src/api/challenges/challenges.service.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,53 @@ describe('ChallengesService', () => {
116116
}),
117117
]);
118118
});
119+
120+
it('maps reviewer payments to TOPGEAR_PAYMENT for topgear challenges', async () => {
121+
const service = new ChallengesService(
122+
{} as any,
123+
{} as any,
124+
{} as any,
125+
{} as any,
126+
{} as any,
127+
);
128+
129+
jest.spyOn(service, 'getChallengeReviews').mockResolvedValue([
130+
{
131+
phaseId: 'phase-resource-1',
132+
phaseName: 'Review',
133+
reviewerHandle: 'reviewer1',
134+
},
135+
] as any);
136+
137+
const payments = await service.generateReviewersPayments(
138+
{
139+
id: '11111111-1111-1111-1111-111111111111',
140+
name: 'Topgear Review Challenge',
141+
metadata: [{ name: 'payment_type', value: 'topgear' }],
142+
prizeSets: [{ type: 'PLACEMENT', prizes: [{ type: PrizeType.USD, value: 500 }] }],
143+
reviewers: [
144+
{
145+
isMemberReview: true,
146+
phaseId: 'review-phase-1',
147+
fixedAmount: 10,
148+
baseCoefficient: 0.1,
149+
incrementalCoefficient: 0.05,
150+
},
151+
],
152+
phases: [{ id: 'phase-resource-1', phaseId: 'review-phase-1' }],
153+
} as any,
154+
[
155+
{
156+
memberHandle: 'reviewer1',
157+
memberId: 123,
158+
},
159+
] as any,
160+
);
161+
162+
expect(payments).toEqual([
163+
expect.objectContaining({
164+
type: WinningsCategory.TOPGEAR_PAYMENT,
165+
}),
166+
]);
167+
});
119168
});

src/api/challenges/challenges.service.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ export class ChallengesService {
7373
private readonly winningsRepo: WinningsRepository,
7474
) {}
7575

76-
private getDefaultWinnerCategory(challenge: Challenge): WinningsCategory {
76+
private getMetadataPaymentCategory(
77+
challenge: Challenge,
78+
): WinningsCategory | undefined {
7779
const metadataPaymentCategory = challenge.metadata?.find(
7880
({ name, value }) =>
7981
name?.toLowerCase() === PAYMENT_TYPE_METADATA_NAME &&
@@ -87,11 +89,35 @@ export class ChallengesService {
8789
];
8890
}
8991

92+
return undefined;
93+
}
94+
95+
private getDefaultWinnerCategory(challenge: Challenge): WinningsCategory {
96+
const metadataPaymentCategory = this.getMetadataPaymentCategory(challenge);
97+
98+
if (metadataPaymentCategory) {
99+
return metadataPaymentCategory;
100+
}
101+
90102
return challenge.task.isTask
91103
? WinningsCategory.TASK_PAYMENT
92104
: WinningsCategory.CONTEST_PAYMENT;
93105
}
94106

107+
private getReviewerPaymentCategory(
108+
challenge: Challenge,
109+
currency?: PrizeType,
110+
): WinningsCategory {
111+
if (currency !== PrizeType.USD) {
112+
return WinningsCategory.POINTS_AWARD;
113+
}
114+
115+
return this.getMetadataPaymentCategory(challenge) ===
116+
WinningsCategory.TOPGEAR_PAYMENT
117+
? WinningsCategory.TOPGEAR_PAYMENT
118+
: WinningsCategory.REVIEW_BOARD_PAYMENT;
119+
}
120+
95121
async getChallenge(challengeId: string) {
96122
if (!isUUID(challengeId)) {
97123
throw new BadRequestException(
@@ -378,10 +404,10 @@ export class ChallengesService {
378404

379405
const placementPrize = placementPrizes?.[0];
380406
const currency = placementPrize?.type;
381-
const winType =
382-
currency === PrizeType.USD
383-
? WinningsCategory.REVIEW_BOARD_PAYMENT
384-
: WinningsCategory.POINTS_AWARD;
407+
const winType = this.getReviewerPaymentCategory(
408+
challenge,
409+
currency,
410+
);
385411

386412
return {
387413
handle: reviewer.memberHandle,

src/api/webhooks/trolley/handlers/recipient-account.types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export interface RecipientAccountEventDataFields {
1717
deliveryBusinessDaysEstimate: number;
1818
}
1919

20-
export interface RecipientAccountEventDataWithBankDetails
21-
extends RecipientAccountEventDataFields {
20+
export interface RecipientAccountEventDataWithBankDetails extends RecipientAccountEventDataFields {
2221
country: string;
2322
iban: string;
2423
accountNum: string;
@@ -37,8 +36,7 @@ export interface RecipientAccountEventDataWithBankDetails
3736
recipientFees: string;
3837
}
3938

40-
export interface RecipientAccountEventDataWithPaypalDetails
41-
extends RecipientAccountEventDataFields {
39+
export interface RecipientAccountEventDataWithPaypalDetails extends RecipientAccountEventDataFields {
4240
emailAddress: string;
4341
}
4442

src/api/winnings/winnings.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ export class WinningsController {
6060
description: 'Create winnings successfully.',
6161
type: ResponseDto<string>,
6262
})
63+
@ApiResponse({
64+
status: 400,
65+
description:
66+
'Invalid winning request or insufficient remaining funds on the billing account.',
67+
})
6368
@HttpCode(HttpStatus.CREATED)
6469
async createWinnings(
6570
@Body() body: WinningCreateRequestDto,

0 commit comments

Comments
 (0)