This commit is contained in:
2025-12-16 21:05:01 +01:00
parent f61e3a4e5a
commit 7532c7ed6d
207 changed files with 7861 additions and 2606 deletions

View File

@@ -1,10 +1,12 @@
/**
* Use Case: RejectSponsorshipRequestUseCase
*
*
* Allows an entity owner to reject a sponsorship request.
*/
import type { ISponsorshipRequestRepository } from '../../domain/repositories/ISponsorshipRequestRepository';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
export interface RejectSponsorshipRequestDTO {
requestId: string;
@@ -24,30 +26,30 @@ export class RejectSponsorshipRequestUseCase {
private readonly sponsorshipRequestRepo: ISponsorshipRequestRepository,
) {}
async execute(dto: RejectSponsorshipRequestDTO): Promise<RejectSponsorshipRequestResultDTO> {
async execute(dto: RejectSponsorshipRequestDTO): Promise<Result<RejectSponsorshipRequestResultDTO, ApplicationErrorCode<'SPONSORSHIP_REQUEST_NOT_FOUND' | 'SPONSORSHIP_REQUEST_NOT_PENDING'>>> {
// Find the request
const request = await this.sponsorshipRequestRepo.findById(dto.requestId);
if (!request) {
throw new Error('Sponsorship request not found');
return Result.err({ code: 'SPONSORSHIP_REQUEST_NOT_FOUND' });
}
if (!request.isPending()) {
throw new Error(`Cannot reject a ${request.status} sponsorship request`);
return Result.err({ code: 'SPONSORSHIP_REQUEST_NOT_PENDING' });
}
// 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 {
return Result.ok({
requestId: rejectedRequest.id,
status: 'rejected',
rejectedAt: rejectedRequest.respondedAt!,
...(rejectedRequest.rejectionReason !== undefined
? { reason: rejectedRequest.rejectionReason }
: {}),
};
});
}
}