harden business rules

This commit is contained in:
2025-12-27 19:18:54 +01:00
parent 0e7a01d81c
commit 8d2b17d9a8
11 changed files with 343 additions and 55 deletions

View File

@@ -221,9 +221,14 @@ export class League implements IEntity<LeagueId> {
// Validate participant count against visibility and max
const participantCount = ParticipantCount.create(props.participantCount ?? 0);
const participantValidation = visibility.validateDriverCount(participantCount.toNumber());
if (!participantValidation.valid) {
throw new RacingDomainValidationError(participantValidation.error!);
// Only validate minimum requirements if there are actual participants
// This allows leagues to be created empty and populated later
if (participantCount.toNumber() > 0) {
const participantValidation = visibility.validateDriverCount(participantCount.toNumber());
if (!participantValidation.valid) {
throw new RacingDomainValidationError(participantValidation.error!);
}
}
if (!maxParticipants.canAccommodate(participantCount.toNumber())) {