Files
gridpilot.gg/core/racing/application/use-cases/GetTotalRacesUseCase.ts
2026-01-16 18:21:06 +01:00

34 lines
1.0 KiB
TypeScript

import { Result } from '@core/shared/domain/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { RaceRepository } from '../../domain/repositories/RaceRepository';
export interface GetTotalRacesInput {}
export type GetTotalRacesErrorCode = 'REPOSITORY_ERROR';
export interface GetTotalRacesResult {
totalRaces: number;
}
export class GetTotalRacesUseCase {
constructor(private readonly raceRepository: RaceRepository) {}
async execute(
_input: GetTotalRacesInput,
): Promise<Result<GetTotalRacesResult, ApplicationErrorCode<GetTotalRacesErrorCode, { message: string }>>> {
void _input;
try {
const races = await this.raceRepository.findAll();
const totalRaces = races.length;
return Result.ok({ totalRaces });
} catch (error: unknown) {
const message = error instanceof Error ? error.message : 'Failed to get total races';
return Result.err({
code: 'REPOSITORY_ERROR',
details: { message },
});
}
}
}