This commit is contained in:
2025-12-11 11:25:22 +01:00
parent 6a427eab57
commit e4c1be628d
86 changed files with 1222 additions and 736 deletions

View File

@@ -1,10 +1,12 @@
/**
* Domain Entity: SeasonSponsorship
*
*
* Represents a sponsorship relationship between a Sponsor and a Season.
* Aggregate root for managing sponsorship slots and pricing.
*/
import { RacingDomainValidationError, RacingDomainInvariantError } from '../errors/RacingDomainError';
import type { Money } from '../value-objects/Money';
export type SponsorshipTier = 'main' | 'secondary';
@@ -60,27 +62,27 @@ export class SeasonSponsorship {
private static validate(props: Omit<SeasonSponsorshipProps, 'createdAt' | 'status'>): void {
if (!props.id || props.id.trim().length === 0) {
throw new Error('SeasonSponsorship ID is required');
throw new RacingDomainValidationError('SeasonSponsorship ID is required');
}
if (!props.seasonId || props.seasonId.trim().length === 0) {
throw new Error('SeasonSponsorship seasonId is required');
throw new RacingDomainValidationError('SeasonSponsorship seasonId is required');
}
if (!props.sponsorId || props.sponsorId.trim().length === 0) {
throw new Error('SeasonSponsorship sponsorId is required');
throw new RacingDomainValidationError('SeasonSponsorship sponsorId is required');
}
if (!props.tier) {
throw new Error('SeasonSponsorship tier is required');
throw new RacingDomainValidationError('SeasonSponsorship tier is required');
}
if (!props.pricing) {
throw new Error('SeasonSponsorship pricing is required');
throw new RacingDomainValidationError('SeasonSponsorship pricing is required');
}
if (props.pricing.amount <= 0) {
throw new Error('SeasonSponsorship pricing must be greater than zero');
throw new RacingDomainValidationError('SeasonSponsorship pricing must be greater than zero');
}
}
@@ -89,11 +91,11 @@ export class SeasonSponsorship {
*/
activate(): SeasonSponsorship {
if (this.status === 'active') {
throw new Error('SeasonSponsorship is already active');
throw new RacingDomainInvariantError('SeasonSponsorship is already active');
}
if (this.status === 'cancelled') {
throw new Error('Cannot activate a cancelled SeasonSponsorship');
throw new RacingDomainInvariantError('Cannot activate a cancelled SeasonSponsorship');
}
return new SeasonSponsorship({
@@ -108,7 +110,7 @@ export class SeasonSponsorship {
*/
cancel(): SeasonSponsorship {
if (this.status === 'cancelled') {
throw new Error('SeasonSponsorship is already cancelled');
throw new RacingDomainInvariantError('SeasonSponsorship is already cancelled');
}
return new SeasonSponsorship({