64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
import type { SponsorsApiClient } from '../../api/sponsors/SponsorsApiClient';
|
|
import { SponsorViewModel, SponsorDashboardViewModel, SponsorSponsorshipsViewModel } from '../../view-models';
|
|
import type { CreateSponsorInputDTO } from '../../types/generated';
|
|
|
|
// TODO: Move these types to apps/website/lib/types/generated when available
|
|
type CreateSponsorOutputDto = { id: string; name: string };
|
|
type GetEntitySponsorshipPricingResultDto = { pricing: Array<{ entityType: string; price: number }> };
|
|
type SponsorDTO = { id: string; name: string; logoUrl?: string; websiteUrl?: string };
|
|
|
|
/**
|
|
* 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();
|
|
}
|
|
} |