120 lines
5.0 KiB
TypeScript
120 lines
5.0 KiB
TypeScript
import { Result } from '@/lib/contracts/Result';
|
|
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
|
import { SponsorsApiClient } from '@/lib/api/sponsors/SponsorsApiClient';
|
|
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
|
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
|
|
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
|
|
import { getWebsiteServerEnv } from '@/lib/config/env';
|
|
import type { SponsorDashboardDTO } from '@/lib/types/generated/SponsorDashboardDTO';
|
|
import type { SponsorSponsorshipsDTO } from '@/lib/types/generated/SponsorSponsorshipsDTO';
|
|
import type { GetSponsorOutputDTO } from '@/lib/types/generated/GetSponsorOutputDTO';
|
|
import type { GetPendingSponsorshipRequestsOutputDTO } from '@/lib/types/generated/GetPendingSponsorshipRequestsOutputDTO';
|
|
import type { SponsorBillingDTO } from '@/lib/types/tbd/SponsorBillingDTO';
|
|
import type { AvailableLeaguesDTO } from '@/lib/types/tbd/AvailableLeaguesDTO';
|
|
import type { LeagueDetailForSponsorDTO } from '@/lib/types/tbd/LeagueDetailForSponsorDTO';
|
|
import type { SponsorSettingsDTO } from '@/lib/types/tbd/SponsorSettingsDTO';
|
|
|
|
/**
|
|
* Sponsor Service - DTO Only
|
|
*
|
|
* Returns raw API DTOs. No ViewModels or UX logic.
|
|
* All client-side presentation logic must be handled by hooks/components.
|
|
*/
|
|
export class SponsorService implements Service {
|
|
private apiClient: SponsorsApiClient;
|
|
|
|
constructor() {
|
|
const baseUrl = getWebsiteApiBaseUrl();
|
|
const logger = new ConsoleLogger();
|
|
const { NODE_ENV } = getWebsiteServerEnv();
|
|
const errorReporter = new EnhancedErrorReporter(logger, {
|
|
showUserNotifications: true,
|
|
logToConsole: true,
|
|
reportToExternal: NODE_ENV === 'production',
|
|
});
|
|
this.apiClient = new SponsorsApiClient(baseUrl, errorReporter, logger);
|
|
}
|
|
|
|
async getSponsorById(sponsorId: string): Promise<Result<GetSponsorOutputDTO, DomainError>> {
|
|
try {
|
|
const result = await this.apiClient.getSponsor(sponsorId);
|
|
if (!result) {
|
|
return Result.err({ type: 'notFound', message: 'Sponsor not found' });
|
|
}
|
|
return Result.ok(result);
|
|
} catch (error) {
|
|
return Result.err({ type: 'unknown', message: 'Failed to get sponsor' });
|
|
}
|
|
}
|
|
|
|
async getSponsorDashboard(sponsorId: string): Promise<Result<SponsorDashboardDTO, DomainError>> {
|
|
try {
|
|
const result = await this.apiClient.getDashboard(sponsorId);
|
|
if (!result) {
|
|
return Result.err({ type: 'notFound', message: 'Dashboard not found' });
|
|
}
|
|
return Result.ok(result);
|
|
} catch (error) {
|
|
return Result.err({ type: 'notImplemented', message: 'getSponsorDashboard' });
|
|
}
|
|
}
|
|
|
|
async getSponsorSponsorships(sponsorId: string): Promise<Result<SponsorSponsorshipsDTO, DomainError>> {
|
|
try {
|
|
const result = await this.apiClient.getSponsorships(sponsorId);
|
|
if (!result) {
|
|
return Result.err({ type: 'notFound', message: 'Sponsorships not found' });
|
|
}
|
|
return Result.ok(result);
|
|
} catch (error) {
|
|
return Result.err({ type: 'notImplemented', message: 'getSponsorSponsorships' });
|
|
}
|
|
}
|
|
|
|
async getBilling(): Promise<Result<SponsorBillingDTO, DomainError>> {
|
|
return Result.err({ type: 'notImplemented', message: 'getBilling' });
|
|
}
|
|
|
|
async getAvailableLeagues(): Promise<Result<AvailableLeaguesDTO, DomainError>> {
|
|
return Result.err({ type: 'notImplemented', message: 'getAvailableLeagues' });
|
|
}
|
|
|
|
async getLeagueDetail(): Promise<Result<LeagueDetailForSponsorDTO, DomainError>> {
|
|
return Result.err({ type: 'notImplemented', message: 'getLeagueDetail' });
|
|
}
|
|
|
|
async getSettings(): Promise<Result<SponsorSettingsDTO, DomainError>> {
|
|
return Result.err({ type: 'notImplemented', message: 'getSettings' });
|
|
}
|
|
|
|
async updateSettings(): Promise<Result<void, DomainError>> {
|
|
return Result.err({ type: 'notImplemented', message: 'updateSettings' });
|
|
}
|
|
|
|
async acceptSponsorshipRequest(requestId: string, sponsorId: string): Promise<Result<void, DomainError>> {
|
|
try {
|
|
await this.apiClient.acceptSponsorshipRequest(requestId, { respondedBy: sponsorId });
|
|
return Result.ok(undefined);
|
|
} catch (error) {
|
|
return Result.err({ type: 'unknown', message: 'Failed to accept sponsorship request' });
|
|
}
|
|
}
|
|
|
|
async rejectSponsorshipRequest(requestId: string, sponsorId: string, reason?: string): Promise<Result<void, DomainError>> {
|
|
try {
|
|
await this.apiClient.rejectSponsorshipRequest(requestId, { respondedBy: sponsorId, reason });
|
|
return Result.ok(undefined);
|
|
} catch (error) {
|
|
return Result.err({ type: 'unknown', message: 'Failed to reject sponsorship request' });
|
|
}
|
|
}
|
|
|
|
async getPendingSponsorshipRequests(input: { entityType: string; entityId: string }): Promise<Result<GetPendingSponsorshipRequestsOutputDTO, DomainError>> {
|
|
try {
|
|
const result = await this.apiClient.getPendingSponsorshipRequests(input);
|
|
return Result.ok(result);
|
|
} catch (error) {
|
|
return Result.err({ type: 'notImplemented', message: 'getPendingSponsorshipRequests' });
|
|
}
|
|
}
|
|
} |