refactor use cases
This commit is contained in:
@@ -5,8 +5,6 @@ import type { ILeagueMembershipRepository } from '../../domain/repositories/ILea
|
||||
import type { IRaceRepository } from '../../domain/repositories/IRaceRepository';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
|
||||
export type GetSeasonSponsorshipsInput = {
|
||||
seasonId: string;
|
||||
};
|
||||
@@ -52,18 +50,15 @@ export type GetSeasonSponsorshipsErrorCode =
|
||||
| 'REPOSITORY_ERROR';
|
||||
|
||||
export class GetSeasonSponsorshipsUseCase {
|
||||
constructor(
|
||||
private readonly seasonSponsorshipRepository: ISeasonSponsorshipRepository,
|
||||
constructor(private readonly seasonSponsorshipRepository: ISeasonSponsorshipRepository,
|
||||
private readonly seasonRepository: ISeasonRepository,
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly leagueMembershipRepository: ILeagueMembershipRepository,
|
||||
private readonly raceRepository: IRaceRepository,
|
||||
private readonly output: UseCaseOutputPort<GetSeasonSponsorshipsResult>,
|
||||
) {}
|
||||
private readonly raceRepository: IRaceRepository) {}
|
||||
|
||||
async execute(
|
||||
input: GetSeasonSponsorshipsInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<GetSeasonSponsorshipsErrorCode, { message: string }>>> {
|
||||
): Promise<Result<GetSeasonSponsorshipsResult, ApplicationErrorCode<GetSeasonSponsorshipsErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const { seasonId } = input;
|
||||
|
||||
@@ -137,12 +132,12 @@ export class GetSeasonSponsorshipsUseCase {
|
||||
return detail;
|
||||
});
|
||||
|
||||
this.output.present({
|
||||
const result: GetSeasonSponsorshipsResult = {
|
||||
seasonId,
|
||||
sponsorships: sponsorshipDetails,
|
||||
});
|
||||
};
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (err) {
|
||||
const error = err as { message?: string } | undefined;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user