Skip to content

Commit a9a31ff

Browse files
committed
♻️ Extract private method to reduce duplication (#1995)
1 parent 4b9e07d commit a9a31ff

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/lib/clients/aizu_online_judge.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ export class AojChallengesApiClient extends AojTasksApiClientBase<ChallengeParam
568568
cacheKey: this.getCacheKey(contestType, round),
569569
endpoint: this.buildEndpoint(['challenges', 'cl', contestType, round]),
570570
errorMessage: `Failed to fetch ${this.getContestTypeLabel(contestType)} ${round} contests from AOJ API`,
571-
validateResponse: (data) =>
572-
'contests' in data && Array.isArray(data.contests) && data.contests.length > 0,
571+
validateResponse: (data) => this.validateApiResponse(data),
573572
transformer: (data) => this.transformToContests(data),
574573
label: `${this.getContestTypeLabel(contestType)} ${round}`,
575574
});
@@ -582,8 +581,7 @@ export class AojChallengesApiClient extends AojTasksApiClientBase<ChallengeParam
582581
cacheKey: this.getCacheKey(contestType, round),
583582
endpoint: this.buildEndpoint(['challenges', 'cl', contestType, round]),
584583
errorMessage: `Failed to fetch ${this.getContestTypeLabel(contestType)} ${round} tasks from AOJ API`,
585-
validateResponse: (data) =>
586-
'contests' in data && Array.isArray(data.contests) && data.contests.length > 0,
584+
validateResponse: (data) => this.validateApiResponse(data),
587585
transformer: (data) => this.transformToTasks(data),
588586
label: `${this.getContestTypeLabel(contestType)} ${round}`,
589587
});
@@ -604,6 +602,10 @@ export class AojChallengesApiClient extends AojTasksApiClientBase<ChallengeParam
604602
return `aoj_${contestType.toLowerCase()}_${round.toLowerCase()}`;
605603
}
606604

605+
private validateApiResponse(data: AOJChallengeContestAPI): boolean {
606+
return 'contests' in data && Array.isArray(data.contests) && data.contests.length > 0;
607+
}
608+
607609
private transformToContests(data: AOJChallengeContestAPI): ContestsForImport {
608610
return data.contests.flatMap((contest: ChallengeContest) =>
609611
contest.days

0 commit comments

Comments
 (0)