This commit is contained in:
2025-12-11 21:06:25 +01:00
parent c49ea2598d
commit ec3ddc3a5c
227 changed files with 3496 additions and 2083 deletions

View File

@@ -56,29 +56,37 @@ export class ApplyForSponsorshipUseCase
}
if (!pricing.acceptingApplications) {
throw new RacingApplicationError('This entity is not currently accepting sponsorship applications');
throw new BusinessRuleViolationError(
'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 RacingApplicationError(`No ${dto.tier} sponsorship slots are available`);
throw new BusinessRuleViolationError(
`No ${dto.tier} sponsorship slots are available`,
);
}
// Check if sponsor already has a pending request for this entity
const hasPending = await this.sponsorshipRequestRepo.hasPendingRequest(
dto.sponsorId,
dto.entityType,
dto.entityId
dto.entityId,
);
if (hasPending) {
throw new RacingApplicationError('You already have a pending sponsorship request for this entity');
throw new BusinessRuleViolationError(
'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 RacingApplicationError(`Offered amount must be at least ${minPrice.format()}`);
throw new BusinessRuleViolationError(
`Offered amount must be at least ${minPrice.format()}`,
);
}
// Create the sponsorship request
@@ -92,7 +100,7 @@ export class ApplyForSponsorshipUseCase
entityId: dto.entityId,
tier: dto.tier,
offeredAmount,
message: dto.message,
...(dto.message !== undefined ? { message: dto.message } : {}),
});
await this.sponsorshipRequestRepo.create(request);