This commit is contained in:
2025-12-10 12:38:55 +01:00
parent 0f7fe67d3c
commit fbbcf414a4
87 changed files with 11972 additions and 390 deletions

View File

@@ -0,0 +1,51 @@
/**
* Use Case: RejectSponsorshipRequestUseCase
*
* Allows an entity owner to reject a sponsorship request.
*/
import type { ISponsorshipRequestRepository } from '../../domain/repositories/ISponsorshipRequestRepository';
export interface RejectSponsorshipRequestDTO {
requestId: string;
respondedBy: string; // driverId of the person rejecting
reason?: string;
}
export interface RejectSponsorshipRequestResultDTO {
requestId: string;
status: 'rejected';
rejectedAt: Date;
reason?: string;
}
export class RejectSponsorshipRequestUseCase {
constructor(
private readonly sponsorshipRequestRepo: ISponsorshipRequestRepository,
) {}
async execute(dto: RejectSponsorshipRequestDTO): Promise<RejectSponsorshipRequestResultDTO> {
// Find the request
const request = await this.sponsorshipRequestRepo.findById(dto.requestId);
if (!request) {
throw new Error('Sponsorship request not found');
}
if (!request.isPending()) {
throw new Error(`Cannot reject a ${request.status} sponsorship request`);
}
// Reject the request
const rejectedRequest = request.reject(dto.respondedBy, dto.reason);
await this.sponsorshipRequestRepo.update(rejectedRequest);
// TODO: In a real implementation, notify the sponsor
return {
requestId: rejectedRequest.id,
status: 'rejected',
rejectedAt: rejectedRequest.respondedAt!,
reason: rejectedRequest.rejectionReason,
};
}
}