website refactor
This commit is contained in:
@@ -1,120 +1,55 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
||||
import { injectable } from 'inversify';
|
||||
import { SponsorsApiClient } from '@/lib/api/sponsors/SponsorsApiClient';
|
||||
import { SponsorViewModel } from '@/lib/view-models/SponsorViewModel';
|
||||
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
|
||||
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 { Service, type DomainError } from '@/lib/contracts/services/Service';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
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.
|
||||
*/
|
||||
@injectable()
|
||||
export class SponsorService implements Service {
|
||||
private apiClient: SponsorsApiClient;
|
||||
private readonly 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',
|
||||
});
|
||||
const errorReporter = new EnhancedErrorReporter(logger);
|
||||
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: unknown) {
|
||||
return Result.err({ type: 'unknown', message: (error as Error).message || 'Failed to get sponsor' });
|
||||
}
|
||||
async getAllSponsors(): Promise<SponsorViewModel[]> {
|
||||
const data = await this.apiClient.getAll();
|
||||
return data.sponsors.map(s => new SponsorViewModel(s));
|
||||
}
|
||||
|
||||
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: unknown) {
|
||||
return Result.err({ type: 'notImplemented', message: (error as Error).message || 'getSponsorDashboard' });
|
||||
const data = await this.apiClient.getDashboard(sponsorId);
|
||||
if (!data) return Result.err({ type: 'notFound', message: 'Sponsor dashboard not found' });
|
||||
return Result.ok(data);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'serverError', message: error instanceof Error ? error.message : 'Unknown error' });
|
||||
}
|
||||
}
|
||||
|
||||
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: unknown) {
|
||||
return Result.err({ type: 'notImplemented', message: (error as Error).message || 'getSponsorSponsorships' });
|
||||
const data = await this.apiClient.getSponsorships(sponsorId);
|
||||
if (!data) return Result.err({ type: 'notFound', message: 'Sponsor sponsorships not found' });
|
||||
return Result.ok(data);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'serverError', message: error instanceof Error ? error.message : 'Unknown error' });
|
||||
}
|
||||
}
|
||||
|
||||
async getBilling(_: string): Promise<Result<SponsorBillingDTO, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'getBilling' });
|
||||
async createSponsor(input: any): Promise<any> {
|
||||
return this.apiClient.create(input);
|
||||
}
|
||||
|
||||
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: unknown) {
|
||||
return Result.err({ type: 'unknown', message: (error as Error).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: unknown) {
|
||||
return Result.err({ type: 'unknown', message: (error as Error).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: unknown) {
|
||||
return Result.err({ type: 'notImplemented', message: (error as Error).message || 'getPendingSponsorshipRequests' });
|
||||
}
|
||||
async getSponsorshipPricing(): Promise<any> {
|
||||
return this.apiClient.getPricing();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user