This commit is contained in:
2025-12-16 21:05:01 +01:00
parent f61e3a4e5a
commit 7532c7ed6d
207 changed files with 7861 additions and 2606 deletions

View File

@@ -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' });
}
}
}