refactor use cases
This commit is contained in:
@@ -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 } });
|
||||
|
||||
Reference in New Issue
Block a user