refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -10,7 +10,6 @@ import type { IRaceRepository } from '../../domain/repositories/IRaceRepository'
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import { randomUUID } from 'crypto';
export type FileProtestErrorCode = 'RACE_NOT_FOUND' | 'SELF_PROTEST' | 'NOT_MEMBER' | 'REPOSITORY_ERROR';
@@ -37,10 +36,9 @@ export class FileProtestUseCase {
private readonly protestRepository: IProtestRepository,
private readonly raceRepository: IRaceRepository,
private readonly leagueMembershipRepository: ILeagueMembershipRepository,
private readonly output: UseCaseOutputPort<FileProtestResult>,
) {}
async execute(command: FileProtestInput): Promise<Result<void, ApplicationErrorCode<FileProtestErrorCode, { message: string }>>> {
async execute(command: FileProtestInput): Promise<Result<FileProtestResult, ApplicationErrorCode<FileProtestErrorCode, { message: string }>>> {
try {
// Validate race exists
const race = await this.raceRepository.findById(command.raceId);
@@ -80,9 +78,9 @@ export class FileProtestUseCase {
await this.protestRepository.create(protest);
this.output.present({ protest });
const result: FileProtestResult = { protest };
return Result.ok(undefined);
return Result.ok(result);
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to file protest';
return Result.err({ code: 'REPOSITORY_ERROR', details: { message } });