refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -1,27 +1,18 @@
import { Result } from '@core/shared/application/Result';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { Game } from '../../domain/entities/Game';
import type { League } from '../../domain/entities/League';
import type { LeagueScoringConfig } from '../../domain/entities/LeagueScoringConfig';
import type { Season } from '../../domain/entities/season/Season';
import type { IGameRepository } from '../../domain/repositories/IGameRepository';
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
import type { ILeagueScoringConfigRepository } from '../../domain/repositories/ILeagueScoringConfigRepository';
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
import type { ISeasonRepository } from '../../domain/repositories/ISeasonRepository';
import type { IGameRepository } from '../../domain/repositories/IGameRepository';
import type { LeagueScoringConfig } from '../../domain/entities/LeagueScoringConfig';
import type { League } from '../../domain/entities/League';
import type { Season } from '../../domain/entities/season/Season';
import type { Game } from '../../domain/entities/Game';
import type { LeagueScoringPreset } from '../../domain/types/LeagueScoringPreset';
export type GetLeagueScoringConfigInput = {
export interface GetLeagueScoringConfigInput {
leagueId: string;
};
export type GetLeagueScoringConfigResult = {
league: League;
season: Season;
scoringConfig: LeagueScoringConfig;
game: Game;
preset?: LeagueScoringPreset;
};
}
export type GetLeagueScoringConfigErrorCode =
| 'LEAGUE_NOT_FOUND'
@@ -31,9 +22,14 @@ export type GetLeagueScoringConfigErrorCode =
| 'GAME_NOT_FOUND'
| 'REPOSITORY_ERROR';
/**
* Use Case for retrieving a league's scoring configuration for its active season.
*/
export interface GetLeagueScoringConfigResult {
league: League;
season: Season;
scoringConfig: LeagueScoringConfig;
game: Game;
preset?: LeagueScoringPreset;
}
export class GetLeagueScoringConfigUseCase {
constructor(
private readonly leagueRepository: ILeagueRepository,
@@ -43,15 +39,12 @@ export class GetLeagueScoringConfigUseCase {
private readonly presetProvider: {
getPresetById(presetId: string): LeagueScoringPreset | undefined;
},
private readonly output: UseCaseOutputPort<GetLeagueScoringConfigResult>,
) {}
async execute(
params: GetLeagueScoringConfigInput,
): Promise<
Result<void, ApplicationErrorCode<GetLeagueScoringConfigErrorCode, { message: string }>>
> {
const { leagueId } = params;
input: GetLeagueScoringConfigInput,
): Promise<Result<GetLeagueScoringConfigResult, ApplicationErrorCode<GetLeagueScoringConfigErrorCode, { message: string }>>> {
const { leagueId } = input;
try {
const league = await this.leagueRepository.findById(leagueId);
@@ -122,9 +115,7 @@ export class GetLeagueScoringConfigUseCase {
...(preset !== undefined ? { preset } : {}),
};
this.output.present(result);
return Result.ok(undefined);
return Result.ok(result);
} catch (error) {
return Result.err({
code: 'REPOSITORY_ERROR',