website refactor
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { describe, it, expect, vi, Mocked } from 'vitest';
|
||||
import { SponsorService } from './SponsorService';
|
||||
import { SponsorsApiClient } from '../../api/sponsors/SponsorsApiClient';
|
||||
import { SponsorViewModel } from '../../view-models/SponsorViewModel';
|
||||
import { SponsorDashboardViewModel } from '../../view-models/SponsorDashboardViewModel';
|
||||
import { SponsorSponsorshipsViewModel } from '../../view-models/SponsorSponsorshipsViewModel';
|
||||
import { SponsorsApiClient } from '@/lib/api/sponsors/SponsorsApiClient';
|
||||
import { SponsorViewModel } from '@/lib/view-models/SponsorViewModel';
|
||||
import { SponsorDashboardViewModel } from '@/lib/view-models/SponsorDashboardViewModel';
|
||||
import { SponsorSponsorshipsViewModel } from '@/lib/view-models/SponsorSponsorshipsViewModel';
|
||||
|
||||
describe('SponsorService', () => {
|
||||
let mockApiClient: Mocked<SponsorsApiClient>;
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
import type { SponsorsApiClient } 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';
|
||||
import type { SponsorDTO } from '../../types/generated/SponsorDTO';
|
||||
|
||||
/**
|
||||
* 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<any> {
|
||||
return await this.apiClient.create(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sponsorship pricing
|
||||
*/
|
||||
async getSponsorshipPricing(): Promise<any> {
|
||||
return await this.apiClient.getPricing();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sponsor billing information
|
||||
*/
|
||||
async getBilling(sponsorId: string): Promise<{
|
||||
paymentMethods: any[];
|
||||
invoices: any[];
|
||||
stats: any;
|
||||
}> {
|
||||
return await this.apiClient.getBilling(sponsorId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available leagues for sponsorship
|
||||
*/
|
||||
async getAvailableLeagues(): Promise<any[]> {
|
||||
return await this.apiClient.getAvailableLeagues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get detailed league information
|
||||
*/
|
||||
async getLeagueDetail(leagueId: string): Promise<{
|
||||
league: any;
|
||||
drivers: any[];
|
||||
races: any[];
|
||||
}> {
|
||||
return await this.apiClient.getLeagueDetail(leagueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sponsor settings
|
||||
*/
|
||||
async getSettings(sponsorId: string): Promise<{
|
||||
profile: any;
|
||||
notifications: any;
|
||||
privacy: any;
|
||||
}> {
|
||||
return await this.apiClient.getSettings(sponsorId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update sponsor settings
|
||||
*/
|
||||
async updateSettings(sponsorId: string, input: any): Promise<void> {
|
||||
return await this.apiClient.updateSettings(sponsorId, input);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, it, expect, vi, Mocked } from 'vitest';
|
||||
import { SponsorshipService } from './SponsorshipService';
|
||||
import { SponsorsApiClient } from '../../api/sponsors/SponsorsApiClient';
|
||||
import { SponsorshipPricingViewModel } from '../../view-models/SponsorshipPricingViewModel';
|
||||
import { SponsorSponsorshipsViewModel } from '../../view-models/SponsorSponsorshipsViewModel';
|
||||
import { SponsorsApiClient } from '@/lib/api/sponsors/SponsorsApiClient';
|
||||
import { SponsorshipPricingViewModel } from '@/lib/view-models/SponsorshipPricingViewModel';
|
||||
import { SponsorSponsorshipsViewModel } from '@/lib/view-models/SponsorSponsorshipsViewModel';
|
||||
|
||||
describe('SponsorshipService', () => {
|
||||
let mockApiClient: Mocked<SponsorsApiClient>;
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
import type { SponsorsApiClient } from '../../api/sponsors/SponsorsApiClient';
|
||||
import { SponsorshipPricingViewModel } from '../../view-models/SponsorshipPricingViewModel';
|
||||
import { SponsorSponsorshipsViewModel } from '../../view-models/SponsorSponsorshipsViewModel';
|
||||
import { SponsorshipRequestViewModel } from '../../view-models/SponsorshipRequestViewModel';
|
||||
import type { GetPendingSponsorshipRequestsOutputDTO } from '../../types/generated/GetPendingSponsorshipRequestsOutputDTO';
|
||||
import type { SponsorshipRequestDTO } from '../../types/generated/SponsorshipRequestDTO';
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
// Pricing shape isn't finalized in the API yet.
|
||||
// Keep a predictable, UI-friendly structure until a dedicated DTO is introduced.
|
||||
const dto = await this.apiClient.getPricing();
|
||||
|
||||
const main =
|
||||
dto.pricing.find((p) => p.entityType === 'league' || p.entityType === 'main')?.price ?? 0;
|
||||
const secondary =
|
||||
dto.pricing.find((p) => p.entityType === 'driver' || p.entityType === 'secondary')?.price ?? 0;
|
||||
|
||||
return new SponsorshipPricingViewModel({
|
||||
mainSlotPrice: main,
|
||||
secondarySlotPrice: secondary,
|
||||
currency: 'USD',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)) as unknown as GetPendingSponsorshipRequestsOutputDTO;
|
||||
const requests = (dto as any).requests as SponsorshipRequestDTO[];
|
||||
return (requests ?? []).map((r: SponsorshipRequestDTO) => new SponsorshipRequestViewModel(r));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ? { reason } : {}) });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user