refactor use cases
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
@@ -25,14 +25,13 @@ export class DeleteLeagueSeasonScheduleRaceUseCase {
|
||||
private readonly seasonRepository: ISeasonRepository,
|
||||
private readonly raceRepository: IRaceRepository,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<DeleteLeagueSeasonScheduleRaceResult>,
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
input: DeleteLeagueSeasonScheduleRaceInput,
|
||||
): Promise<
|
||||
Result<
|
||||
void,
|
||||
DeleteLeagueSeasonScheduleRaceResult,
|
||||
ApplicationErrorCode<DeleteLeagueSeasonScheduleRaceErrorCode, { message: string }>
|
||||
>
|
||||
> {
|
||||
@@ -51,8 +50,8 @@ export class DeleteLeagueSeasonScheduleRaceUseCase {
|
||||
});
|
||||
}
|
||||
|
||||
const existing = await this.raceRepository.findById(input.raceId);
|
||||
if (!existing || existing.leagueId !== input.leagueId) {
|
||||
const race = await this.raceRepository.findById(input.raceId);
|
||||
if (!race || race.leagueId !== input.leagueId) {
|
||||
return Result.err({
|
||||
code: 'RACE_NOT_FOUND',
|
||||
details: { message: 'Race not found for league' },
|
||||
@@ -62,9 +61,7 @@ export class DeleteLeagueSeasonScheduleRaceUseCase {
|
||||
await this.raceRepository.delete(input.raceId);
|
||||
|
||||
const result: DeleteLeagueSeasonScheduleRaceResult = { success: true };
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (err) {
|
||||
const error = err instanceof Error ? err : new Error('Unknown error');
|
||||
this.logger.error('Failed to delete league season schedule race', error, {
|
||||
|
||||
Reference in New Issue
Block a user