refactor core presenters
This commit is contained in:
@@ -2,29 +2,24 @@ import type { ILeagueRepository } from '../../domain/repositories/ILeagueReposit
|
||||
import type { ISeasonRepository } from '../../domain/repositories/ISeasonRepository';
|
||||
import type { ILeagueScoringConfigRepository } from '../../domain/repositories/ILeagueScoringConfigRepository';
|
||||
import type { IGameRepository } from '../../domain/repositories/IGameRepository';
|
||||
import type {
|
||||
ILeagueFullConfigPresenter,
|
||||
LeagueFullConfigData,
|
||||
LeagueConfigFormViewModel,
|
||||
} from '../presenters/ILeagueFullConfigPresenter';
|
||||
import type { LeagueFullConfigOutputPort } from '../ports/output/LeagueFullConfigOutputPort';
|
||||
import type { AsyncUseCase } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
/**
|
||||
* Use Case for retrieving a league's full configuration.
|
||||
* Orchestrates domain logic and delegates presentation to the presenter.
|
||||
* Orchestrates domain logic and returns the configuration data.
|
||||
*/
|
||||
export class GetLeagueFullConfigUseCase implements AsyncUseCase<{ leagueId: string }, LeagueConfigFormViewModel, 'LEAGUE_NOT_FOUND' | 'PRESENTATION_FAILED'> {
|
||||
export class GetLeagueFullConfigUseCase implements AsyncUseCase<{ leagueId: string }, LeagueFullConfigOutputPort, 'LEAGUE_NOT_FOUND'> {
|
||||
constructor(
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly seasonRepository: ISeasonRepository,
|
||||
private readonly leagueScoringConfigRepository: ILeagueScoringConfigRepository,
|
||||
private readonly gameRepository: IGameRepository,
|
||||
private readonly presenter: ILeagueFullConfigPresenter,
|
||||
) {}
|
||||
|
||||
async execute(params: { leagueId: string }): Promise<Result<LeagueConfigFormViewModel, ApplicationErrorCode<'LEAGUE_NOT_FOUND' | 'PRESENTATION_FAILED', { message: string }>>> {
|
||||
async execute(params: { leagueId: string }): Promise<Result<LeagueFullConfigOutputPort, ApplicationErrorCode<'LEAGUE_NOT_FOUND', { message: string }>>> {
|
||||
const { leagueId } = params;
|
||||
|
||||
const league = await this.leagueRepository.findById(leagueId);
|
||||
@@ -47,20 +42,13 @@ export class GetLeagueFullConfigUseCase implements AsyncUseCase<{ leagueId: stri
|
||||
return this.gameRepository.findById(activeSeason.gameId);
|
||||
})();
|
||||
|
||||
const data: LeagueFullConfigData = {
|
||||
const output: LeagueFullConfigOutputPort = {
|
||||
league,
|
||||
...(activeSeason ? { activeSeason } : {}),
|
||||
...(scoringConfig ? { scoringConfig } : {}),
|
||||
...(game ? { game } : {}),
|
||||
};
|
||||
|
||||
this.presenter.reset();
|
||||
this.presenter.present(data);
|
||||
const viewModel = this.presenter.getViewModel();
|
||||
if (!viewModel) {
|
||||
return Result.err({ code: 'PRESENTATION_FAILED', details: { message: 'Failed to present league config' } });
|
||||
}
|
||||
|
||||
return Result.ok(viewModel);
|
||||
return Result.ok(output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user