refactor use cases
This commit is contained in:
@@ -14,7 +14,6 @@ import { WeekdaySet } from '../../domain/value-objects/WeekdaySet';
|
||||
import { MonthlyRecurrencePattern } from '../../domain/value-objects/MonthlyRecurrencePattern';
|
||||
import type { Weekday } from '../../domain/types/Weekday';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
@@ -99,12 +98,16 @@ export class CreateSeasonForLeagueUseCase {
|
||||
constructor(
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly seasonRepository: ISeasonRepository,
|
||||
private readonly output: UseCaseOutputPort<CreateSeasonForLeagueResult>,
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
input: CreateSeasonForLeagueInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<CreateSeasonForLeagueErrorCode>>> {
|
||||
): Promise<
|
||||
Result<
|
||||
CreateSeasonForLeagueResult,
|
||||
ApplicationErrorCode<CreateSeasonForLeagueErrorCode>
|
||||
>
|
||||
> {
|
||||
try {
|
||||
const league = await this.leagueRepository.findById(input.leagueId);
|
||||
if (!league) {
|
||||
@@ -159,9 +162,12 @@ export class CreateSeasonForLeagueUseCase {
|
||||
|
||||
await this.seasonRepository.add(season);
|
||||
|
||||
this.output.present({ league, season });
|
||||
const result: CreateSeasonForLeagueResult = {
|
||||
league,
|
||||
season,
|
||||
};
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({
|
||||
code: 'REPOSITORY_ERROR',
|
||||
@@ -290,4 +296,4 @@ export class CreateSeasonForLeagueUseCase {
|
||||
plannedRounds: plannedRounds ?? 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user