services refactor
This commit is contained in:
@@ -1,17 +1,65 @@
|
||||
import { api as api } from '../../api';
|
||||
import { presentSponsor } from '../../presenters';
|
||||
import { SponsorViewModel } from '../../view-models';
|
||||
import type { SponsorsApiClient } from '../../api/sponsors/SponsorsApiClient';
|
||||
import type { SponsorListPresenter } from '../../presenters/SponsorListPresenter';
|
||||
import type { SponsorDashboardPresenter } from '../../presenters/SponsorDashboardPresenter';
|
||||
import type { SponsorSponsorshipsPresenter } from '../../presenters/SponsorSponsorshipsPresenter';
|
||||
import type { SponsorViewModel, SponsorDashboardViewModel, SponsorSponsorshipsViewModel } from '../../view-models';
|
||||
import type { CreateSponsorInputDto, CreateSponsorOutputDto, GetEntitySponsorshipPricingResultDto } from '../../dtos';
|
||||
|
||||
export async function getAllSponsors(): Promise<SponsorViewModel[]> {
|
||||
const dto = await api.sponsors.getAll();
|
||||
return dto.sponsors.map(s => presentSponsor(s));
|
||||
}
|
||||
/**
|
||||
* Sponsor Service
|
||||
*
|
||||
* Orchestrates sponsor operations by coordinating API calls and presentation logic.
|
||||
* All dependencies are injected via constructor.
|
||||
*/
|
||||
export class SponsorService {
|
||||
constructor(
|
||||
private readonly apiClient: SponsorsApiClient,
|
||||
private readonly sponsorListPresenter: SponsorListPresenter,
|
||||
private readonly sponsorDashboardPresenter: SponsorDashboardPresenter,
|
||||
private readonly sponsorSponsorshipsPresenter: SponsorSponsorshipsPresenter
|
||||
) {}
|
||||
|
||||
export async function createSponsor(input: any): Promise<any> {
|
||||
return await api.sponsors.create(input);
|
||||
}
|
||||
/**
|
||||
* Get all sponsors with presentation transformation
|
||||
*/
|
||||
async getAllSponsors(): Promise<SponsorViewModel[]> {
|
||||
const dto = await this.apiClient.getAll();
|
||||
return this.sponsorListPresenter.present(dto);
|
||||
}
|
||||
|
||||
export async function getSponsorDashboard(sponsorId: string): Promise<any> {
|
||||
const dto = await api.sponsors.getDashboard(sponsorId);
|
||||
return dto;
|
||||
/**
|
||||
* Get sponsor dashboard with presentation transformation
|
||||
*/
|
||||
async getSponsorDashboard(sponsorId: string): Promise<SponsorDashboardViewModel | null> {
|
||||
const dto = await this.apiClient.getDashboard(sponsorId);
|
||||
if (!dto) {
|
||||
return null;
|
||||
}
|
||||
return this.sponsorDashboardPresenter.present(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sponsor sponsorships with presentation transformation
|
||||
*/
|
||||
async getSponsorSponsorships(sponsorId: string): Promise<SponsorSponsorshipsViewModel | null> {
|
||||
const dto = await this.apiClient.getSponsorships(sponsorId);
|
||||
if (!dto) {
|
||||
return null;
|
||||
}
|
||||
return this.sponsorSponsorshipsPresenter.present(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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user