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

@@ -11,6 +11,10 @@ import type { ISponsorshipRequestRepository } from '../../domain/repositories/IS
import type { ISponsorshipPricingRepository } from '../../domain/repositories/ISponsorshipPricingRepository';
import type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository';
import { Money, type Currency } from '../../domain/value-objects/Money';
import {
EntityNotFoundError,
BusinessRuleViolationError,
} from '../errors/RacingApplicationError';
export interface ApplyForSponsorshipDTO {
sponsorId: string;
@@ -39,23 +43,23 @@ export class ApplyForSponsorshipUseCase {
// Validate sponsor exists
const sponsor = await this.sponsorRepo.findById(dto.sponsorId);
if (!sponsor) {
throw new Error('Sponsor not found');
throw new EntityNotFoundError({ entity: 'sponsor', id: dto.sponsorId });
}
// Check if entity accepts sponsorship applications
const pricing = await this.sponsorshipPricingRepo.findByEntity(dto.entityType, dto.entityId);
if (!pricing) {
throw new Error('This entity has not set up sponsorship pricing');
throw new BusinessRuleViolationError('This entity has not set up sponsorship pricing');
}
if (!pricing.acceptingApplications) {
throw new Error('This entity is not currently accepting sponsorship applications');
throw new RacingApplicationError('This entity is not currently accepting sponsorship applications');
}
// Check if the requested tier slot is available
const slotAvailable = pricing.isSlotAvailable(dto.tier);
if (!slotAvailable) {
throw new Error(`No ${dto.tier} sponsorship slots are available`);
throw new RacingApplicationError(`No ${dto.tier} sponsorship slots are available`);
}
// Check if sponsor already has a pending request for this entity
@@ -65,13 +69,13 @@ export class ApplyForSponsorshipUseCase {
dto.entityId
);
if (hasPending) {
throw new Error('You already have a pending sponsorship request for this entity');
throw new RacingApplicationError('You already have a pending sponsorship request for this entity');
}
// Validate offered amount meets minimum price
const minPrice = pricing.getPrice(dto.tier);
if (minPrice && dto.offeredAmount < minPrice.amount) {
throw new Error(`Offered amount must be at least ${minPrice.format()}`);
throw new RacingApplicationError(`Offered amount must be at least ${minPrice.format()}`);
}
// Create the sponsorship request