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
5 changes: 4 additions & 1 deletion src/api/challenges/challenges.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export class ChallengesController {
);
result.status = ResponseStatusType.SUCCESS;
} catch (e) {
result.error = e;
result.error = {
...e,
message: e.message,
};
result.status = ResponseStatusType.ERROR;
}

Expand Down
16 changes: 16 additions & 0 deletions src/api/challenges/challenges.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,22 @@ export class ChallengesService {
);
}

const paymentTypes = [
...new Set(

Choose a reason for hiding this comment

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

[⚠️ performance]
Using new Set followed by spreading into an array is a common pattern for deduplication, but it might be more efficient to use a single reduce operation to build the array directly without intermediate structures. Consider using reduce to accumulate unique payment types.

challenge.prizeSets
.map((set) => set.prizes.map((prize) => prize.type))
.flat(),
),
];
const isRewardsPayment = paymentTypes.some((type) => type !== 'USD');

Choose a reason for hiding this comment

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

[❗❗ correctness]
The variable isRewardsPayment is determined by checking if any payment type is not 'USD'. This logic might be misleading if there are mixed types (e.g., both 'USD' and another type). Ensure that the logic aligns with the intended business rule.


if (isRewardsPayment) {
this.logger.log(
`Rewards system detected: ${paymentTypes.join(', ')}. Skipping payments generation for challenge ${challenge.name} (${challenge.id}).`,
);
return;
}

const payments = await this.getChallengePayments(challenge);
const totalAmount = payments.reduce(
(sum, payment) => sum + payment.details[0].totalAmount,
Expand Down