wip
This commit is contained in:
32
packages/racing/application/use-cases/CancelRaceUseCase.ts
Normal file
32
packages/racing/application/use-cases/CancelRaceUseCase.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { IRaceRepository } from '../../domain/repositories/IRaceRepository';
|
||||
|
||||
/**
|
||||
* Use Case: CancelRaceUseCase
|
||||
*
|
||||
* Encapsulates the workflow for cancelling a race:
|
||||
* - loads the race by id
|
||||
* - throws if the race does not exist
|
||||
* - delegates cancellation rules to the Race domain entity
|
||||
* - persists the updated race via the repository.
|
||||
*/
|
||||
export interface CancelRaceCommandDTO {
|
||||
raceId: string;
|
||||
}
|
||||
|
||||
export class CancelRaceUseCase {
|
||||
constructor(
|
||||
private readonly raceRepository: IRaceRepository,
|
||||
) {}
|
||||
|
||||
async execute(command: CancelRaceCommandDTO): Promise<void> {
|
||||
const { raceId } = command;
|
||||
|
||||
const race = await this.raceRepository.findById(raceId);
|
||||
if (!race) {
|
||||
throw new Error('Race not found');
|
||||
}
|
||||
|
||||
const cancelledRace = race.cancel();
|
||||
await this.raceRepository.update(cancelledRace);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user