Files
gridpilot.gg/core/racing/application/use-cases/GetLeagueAdminUseCase.ts
2025-12-16 18:17:48 +01:00

27 lines
1.1 KiB
TypeScript

import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
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 class GetLeagueAdminUseCase implements AsyncUseCase<GetLeagueAdminUseCaseParams, Result<GetLeagueAdminResultDTO, RacingDomainValidationError>> {
constructor(
private readonly leagueRepository: ILeagueRepository,
) {}
async execute(params: GetLeagueAdminUseCaseParams): Promise<Result<GetLeagueAdminResultDTO, RacingDomainValidationError>> {
const league = await this.leagueRepository.findById(params.leagueId);
if (!league) {
return Result.err(new RacingDomainValidationError('League not found'));
}
const dto: GetLeagueAdminResultDTO = {
league: {
id: league.id,
ownerId: league.ownerId,
},
};
return Result.ok(dto);
}
}