refactor
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { IRaceRegistrationRepository } from '@core/racing/domain/repositories/IRaceRegistrationRepository';
|
||||
import type { WithdrawFromRaceCommandDTO } from '../dto/WithdrawFromRaceCommandDTO';
|
||||
|
||||
/**
|
||||
* Mirrors legacy withdrawFromRace behavior:
|
||||
* - throws when driver is not registered
|
||||
* - returns error when driver is not registered
|
||||
* - removes registration and cleans up empty race sets
|
||||
*
|
||||
* The repository encapsulates the in-memory or persistent details.
|
||||
@@ -13,10 +15,14 @@ export class WithdrawFromRaceUseCase {
|
||||
private readonly registrationRepository: IRaceRegistrationRepository,
|
||||
) {}
|
||||
|
||||
async execute(command: WithdrawFromRaceCommandDTO): Promise<void> {
|
||||
async execute(command: WithdrawFromRaceCommandDTO): Promise<Result<void, ApplicationErrorCode<'NOT_REGISTERED'>>> {
|
||||
const { raceId, driverId } = command;
|
||||
|
||||
// Let repository enforce "not registered" error behavior to match legacy logic.
|
||||
await this.registrationRepository.withdraw(raceId, driverId);
|
||||
try {
|
||||
await this.registrationRepository.withdraw(raceId, driverId);
|
||||
return Result.ok(undefined);
|
||||
} catch {
|
||||
return Result.err({ code: 'NOT_REGISTERED' });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user