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

@@ -5,6 +5,8 @@
* (driver, team, race, or league/season). The entity owner must approve/reject.
*/
import { RacingDomainValidationError, RacingDomainInvariantError } from '../errors/RacingDomainError';
import type { Money } from '../value-objects/Money';
import type { SponsorshipTier } from './SeasonSponsorship';
@@ -70,31 +72,31 @@ export class SponsorshipRequest {
private static validate(props: Omit<SponsorshipRequestProps, 'createdAt' | 'status'>): void {
if (!props.id || props.id.trim().length === 0) {
throw new Error('SponsorshipRequest ID is required');
throw new RacingDomainValidationError('SponsorshipRequest ID is required');
}
if (!props.sponsorId || props.sponsorId.trim().length === 0) {
throw new Error('SponsorshipRequest sponsorId is required');
throw new RacingDomainValidationError('SponsorshipRequest sponsorId is required');
}
if (!props.entityType) {
throw new Error('SponsorshipRequest entityType is required');
throw new RacingDomainValidationError('SponsorshipRequest entityType is required');
}
if (!props.entityId || props.entityId.trim().length === 0) {
throw new Error('SponsorshipRequest entityId is required');
throw new RacingDomainValidationError('SponsorshipRequest entityId is required');
}
if (!props.tier) {
throw new Error('SponsorshipRequest tier is required');
throw new RacingDomainValidationError('SponsorshipRequest tier is required');
}
if (!props.offeredAmount) {
throw new Error('SponsorshipRequest offeredAmount is required');
throw new RacingDomainValidationError('SponsorshipRequest offeredAmount is required');
}
if (props.offeredAmount.amount <= 0) {
throw new Error('SponsorshipRequest offeredAmount must be greater than zero');
throw new RacingDomainValidationError('SponsorshipRequest offeredAmount must be greater than zero');
}
}
@@ -103,11 +105,11 @@ export class SponsorshipRequest {
*/
accept(respondedBy: string): SponsorshipRequest {
if (this.status !== 'pending') {
throw new Error(`Cannot accept a ${this.status} sponsorship request`);
throw new RacingDomainInvariantError(`Cannot accept a ${this.status} sponsorship request`);
}
if (!respondedBy || respondedBy.trim().length === 0) {
throw new Error('respondedBy is required when accepting');
throw new RacingDomainValidationError('respondedBy is required when accepting');
}
return new SponsorshipRequest({
@@ -123,11 +125,11 @@ export class SponsorshipRequest {
*/
reject(respondedBy: string, reason?: string): SponsorshipRequest {
if (this.status !== 'pending') {
throw new Error(`Cannot reject a ${this.status} sponsorship request`);
throw new RacingDomainInvariantError(`Cannot reject a ${this.status} sponsorship request`);
}
if (!respondedBy || respondedBy.trim().length === 0) {
throw new Error('respondedBy is required when rejecting');
throw new RacingDomainValidationError('respondedBy is required when rejecting');
}
return new SponsorshipRequest({
@@ -144,7 +146,7 @@ export class SponsorshipRequest {
*/
withdraw(): SponsorshipRequest {
if (this.status !== 'pending') {
throw new Error(`Cannot withdraw a ${this.status} sponsorship request`);
throw new RacingDomainInvariantError(`Cannot withdraw a ${this.status} sponsorship request`);
}
return new SponsorshipRequest({