refactor
This commit is contained in:
@@ -1,29 +1,19 @@
|
||||
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import { GetLeagueAdminPermissionsViewModel } from '../presenters/IGetLeagueAdminPermissionsPresenter';
|
||||
import type { IGetLeagueAdminPresenter } from '../presenters/IGetLeagueAdminPresenter';
|
||||
import type { UseCase } from '@core/shared/application/UseCase';
|
||||
import type { AsyncUseCase } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/result/Result';
|
||||
import { RacingDomainValidationError } from '../../domain/errors/RacingDomainError';
|
||||
import type { GetLeagueAdminUseCaseParams } from './GetLeagueAdminUseCaseParams';
|
||||
import type { GetLeagueAdminResultDTO } from '../dto/GetLeagueAdminResultDTO';
|
||||
|
||||
export interface GetLeagueAdminUseCaseParams {
|
||||
leagueId: string;
|
||||
}
|
||||
|
||||
export interface GetLeagueAdminResultDTO {
|
||||
league: {
|
||||
id: string;
|
||||
ownerId: string;
|
||||
};
|
||||
// Additional data would be populated by combining multiple use cases
|
||||
}
|
||||
|
||||
export class GetLeagueAdminUseCase implements UseCase<GetLeagueAdminUseCaseParams, GetLeagueAdminResultDTO, GetLeagueAdminPermissionsViewModel, IGetLeagueAdminPresenter> {
|
||||
export class GetLeagueAdminUseCase implements AsyncUseCase<GetLeagueAdminUseCaseParams, Result<GetLeagueAdminResultDTO, RacingDomainValidationError>> {
|
||||
constructor(
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
) {}
|
||||
|
||||
async execute(params: GetLeagueAdminUseCaseParams, presenter: IGetLeagueAdminPresenter): Promise<void> {
|
||||
async execute(params: GetLeagueAdminUseCaseParams): Promise<Result<GetLeagueAdminResultDTO, RacingDomainValidationError>> {
|
||||
const league = await this.leagueRepository.findById(params.leagueId);
|
||||
if (!league) {
|
||||
throw new Error('League not found');
|
||||
return Result.err(new RacingDomainValidationError('League not found'));
|
||||
}
|
||||
|
||||
const dto: GetLeagueAdminResultDTO = {
|
||||
@@ -32,7 +22,6 @@ export class GetLeagueAdminUseCase implements UseCase<GetLeagueAdminUseCaseParam
|
||||
ownerId: league.ownerId,
|
||||
},
|
||||
};
|
||||
presenter.reset();
|
||||
presenter.present(dto);
|
||||
return Result.ok(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user