Files
gridpilot.gg/apps/website/lib/services/sponsors/SponsorshipService.ts
2025-12-24 13:04:18 +01:00

59 lines
2.1 KiB
TypeScript

import type { SponsorsApiClient } from '../../api/sponsors/SponsorsApiClient';
import type { GetEntitySponsorshipPricingResultDto } from '../../api/sponsors/SponsorsApiClient';
import { SponsorshipPricingViewModel } from '../../view-models/SponsorshipPricingViewModel';
import { SponsorSponsorshipsViewModel } from '../../view-models/SponsorSponsorshipsViewModel';
import { SponsorshipRequestViewModel } from '../../view-models/SponsorshipRequestViewModel';
import type { SponsorSponsorshipsDTO } from '../../types/generated';
/**
* Sponsorship Service
*
* Orchestrates sponsorship operations by coordinating API calls and view model creation.
* All dependencies are injected via constructor.
*/
export class SponsorshipService {
constructor(
private readonly apiClient: SponsorsApiClient
) {}
/**
* Get sponsorship pricing with view model transformation
*/
async getSponsorshipPricing(): Promise<SponsorshipPricingViewModel> {
const dto = await this.apiClient.getPricing();
return new SponsorshipPricingViewModel(dto);
}
/**
* Get sponsor sponsorships with view model transformation
*/
async getSponsorSponsorships(sponsorId: string): Promise<SponsorSponsorshipsViewModel | null> {
const dto = await this.apiClient.getSponsorships(sponsorId);
if (!dto) {
return null;
}
return new SponsorSponsorshipsViewModel(dto);
}
/**
* Get pending sponsorship requests for an entity
*/
async getPendingSponsorshipRequests(params: { entityType: string; entityId: string }): Promise<SponsorshipRequestViewModel[]> {
const dto = await this.apiClient.getPendingSponsorshipRequests(params);
return dto.requests.map(dto => new SponsorshipRequestViewModel(dto));
}
/**
* Accept a sponsorship request
*/
async acceptSponsorshipRequest(requestId: string, respondedBy: string): Promise<void> {
await this.apiClient.acceptSponsorshipRequest(requestId, respondedBy);
}
/**
* Reject a sponsorship request
*/
async rejectSponsorshipRequest(requestId: string, respondedBy: string, reason?: string): Promise<void> {
await this.apiClient.rejectSponsorshipRequest(requestId, respondedBy, reason);
}
}