26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
|
import type { AsyncUseCase } from '@core/shared/application';
|
|
import { Result } from '@core/shared/application/Result';
|
|
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
|
import type { GetLeagueAdminResultDTO } from '../dto/GetLeagueAdminResultDTO';
|
|
|
|
export class GetLeagueAdminUseCase implements AsyncUseCase<{ leagueId: string }, GetLeagueAdminResultDTO, 'LEAGUE_NOT_FOUND'> {
|
|
constructor(
|
|
private readonly leagueRepository: ILeagueRepository,
|
|
) {}
|
|
|
|
async execute(params: { leagueId: string }): Promise<Result<GetLeagueAdminResultDTO, ApplicationErrorCode<'LEAGUE_NOT_FOUND', { message: string }>>> {
|
|
const league = await this.leagueRepository.findById(params.leagueId);
|
|
if (!league) {
|
|
return Result.err({ code: 'LEAGUE_NOT_FOUND', details: { message: 'League not found' } });
|
|
}
|
|
|
|
const dto: GetLeagueAdminResultDTO = {
|
|
league: {
|
|
id: league.id,
|
|
ownerId: league.ownerId,
|
|
},
|
|
};
|
|
return Result.ok(dto);
|
|
}
|
|
} |