61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import type { SponsorsApiClient, CreateSponsorOutputDto, GetEntitySponsorshipPricingResultDto, SponsorDTO } from '../../api/sponsors/SponsorsApiClient';
|
|
import { SponsorViewModel } from '../../view-models/SponsorViewModel';
|
|
import { SponsorDashboardViewModel } from '../../view-models/SponsorDashboardViewModel';
|
|
import { SponsorSponsorshipsViewModel } from '../../view-models/SponsorSponsorshipsViewModel';
|
|
import type { CreateSponsorInputDTO } from '../../types/generated/CreateSponsorInputDTO';
|
|
|
|
/**
|
|
* Sponsor Service
|
|
*
|
|
* Orchestrates sponsor operations by coordinating API calls and view model creation.
|
|
* All dependencies are injected via constructor.
|
|
*/
|
|
export class SponsorService {
|
|
constructor(
|
|
private readonly apiClient: SponsorsApiClient
|
|
) {}
|
|
|
|
/**
|
|
* Get all sponsors with view model transformation
|
|
*/
|
|
async getAllSponsors(): Promise<SponsorViewModel[]> {
|
|
const dto = await this.apiClient.getAll();
|
|
return dto.sponsors.map((sponsor: SponsorDTO) => new SponsorViewModel(sponsor));
|
|
}
|
|
|
|
/**
|
|
* Get sponsor dashboard with view model transformation
|
|
*/
|
|
async getSponsorDashboard(sponsorId: string): Promise<SponsorDashboardViewModel | null> {
|
|
const dto = await this.apiClient.getDashboard(sponsorId);
|
|
if (!dto) {
|
|
return null;
|
|
}
|
|
return new SponsorDashboardViewModel(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);
|
|
}
|
|
|
|
/**
|
|
* Create a new sponsor
|
|
*/
|
|
async createSponsor(input: CreateSponsorInputDTO): Promise<CreateSponsorOutputDto> {
|
|
return await this.apiClient.create(input);
|
|
}
|
|
|
|
/**
|
|
* Get sponsorship pricing
|
|
*/
|
|
async getSponsorshipPricing(): Promise<GetEntitySponsorshipPricingResultDto> {
|
|
return await this.apiClient.getPricing();
|
|
}
|
|
} |