refactor use cases
This commit is contained in:
@@ -2,7 +2,6 @@ import type { IRaceRepository } from '../../domain/repositories/IRaceRepository'
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { Race } from '../../domain/entities/Race';
|
||||
|
||||
export type CancelRaceInput = {
|
||||
@@ -29,11 +28,10 @@ export class CancelRaceUseCase {
|
||||
constructor(
|
||||
private readonly raceRepository: IRaceRepository,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<CancelRaceResult>,
|
||||
) {}
|
||||
|
||||
async execute(command: CancelRaceInput): Promise<
|
||||
Result<void, ApplicationErrorCode<CancelRaceErrorCode>>
|
||||
Result<CancelRaceResult, ApplicationErrorCode<CancelRaceErrorCode, { message: string }>>
|
||||
> {
|
||||
const { raceId } = command;
|
||||
this.logger.debug(`[CancelRaceUseCase] Executing for raceId: ${raceId}`);
|
||||
@@ -56,9 +54,7 @@ export class CancelRaceUseCase {
|
||||
race: cancelledRace,
|
||||
};
|
||||
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes('already cancelled')) {
|
||||
this.logger.warn(`[CancelRaceUseCase] Domain error cancelling race ${raceId}: ${error.message}`);
|
||||
|
||||
Reference in New Issue
Block a user