website refactor

This commit is contained in:
2026-01-14 16:28:39 +01:00
parent 85e09b6f4d
commit 4b7d82ab43
119 changed files with 2403 additions and 1615 deletions

View File

@@ -1,5 +1,18 @@
import { Result } from '@/lib/contracts/Result';
import { DomainError } from '@/lib/contracts/services/Service';
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
@@ -7,100 +20,96 @@ import { DomainError } from '@/lib/contracts/services/Service';
* Returns raw API DTOs. No ViewModels or UX logic.
* All client-side presentation logic must be handled by hooks/components.
*/
export class SponsorService {
constructor(private readonly apiClient: any) {}
export class SponsorService implements Service {
private apiClient: SponsorsApiClient;
async getSponsorById(sponsorId: string): Promise<Result<any, DomainError>> {
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: 'notImplemented', message: 'getSponsorById' });
return Result.err({ type: 'unknown', message: 'Failed to get sponsor' });
}
}
async getSponsorDashboard(sponsorId: string): Promise<Result<any, DomainError>> {
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<any, DomainError>> {
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(sponsorId: string): Promise<Result<any, DomainError>> {
try {
const result = await this.apiClient.getBilling(sponsorId);
return Result.ok(result);
} catch (error) {
return Result.err({ type: 'notImplemented', message: 'getBilling' });
}
async getBilling(): Promise<Result<SponsorBillingDTO, DomainError>> {
return Result.err({ type: 'notImplemented', message: 'getBilling' });
}
async getAvailableLeagues(): Promise<Result<any, DomainError>> {
try {
const result = await this.apiClient.getAvailableLeagues();
return Result.ok(result);
} catch (error) {
return Result.err({ type: 'notImplemented', message: 'getAvailableLeagues' });
}
async getAvailableLeagues(): Promise<Result<AvailableLeaguesDTO, DomainError>> {
return Result.err({ type: 'notImplemented', message: 'getAvailableLeagues' });
}
async getLeagueDetail(leagueId: string): Promise<Result<any, DomainError>> {
try {
const result = await this.apiClient.getLeagueDetail(leagueId);
return Result.ok(result);
} catch (error) {
return Result.err({ type: 'notImplemented', message: 'getLeagueDetail' });
}
async getLeagueDetail(): Promise<Result<LeagueDetailForSponsorDTO, DomainError>> {
return Result.err({ type: 'notImplemented', message: 'getLeagueDetail' });
}
async getSettings(sponsorId: string): Promise<Result<any, DomainError>> {
try {
const result = await this.apiClient.getSettings(sponsorId);
return Result.ok(result);
} catch (error) {
return Result.err({ type: 'notImplemented', message: 'getSettings' });
}
async getSettings(): Promise<Result<SponsorSettingsDTO, DomainError>> {
return Result.err({ type: 'notImplemented', message: 'getSettings' });
}
async updateSettings(sponsorId: string, input: any): Promise<Result<void, DomainError>> {
try {
await this.apiClient.updateSettings(sponsorId, input);
return Result.ok(undefined);
} catch (error) {
return Result.err({ type: 'notImplemented', message: 'updateSettings' });
}
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, sponsorId);
await this.apiClient.acceptSponsorshipRequest(requestId, { respondedBy: sponsorId });
return Result.ok(undefined);
} catch (error) {
return Result.err({ type: 'notImplemented', message: 'acceptSponsorshipRequest' });
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, sponsorId, reason);
await this.apiClient.rejectSponsorshipRequest(requestId, { respondedBy: sponsorId, reason });
return Result.ok(undefined);
} catch (error) {
return Result.err({ type: 'notImplemented', message: 'rejectSponsorshipRequest' });
return Result.err({ type: 'unknown', message: 'Failed to reject sponsorship request' });
}
}
async getPendingSponsorshipRequests(input: any): Promise<Result<any, DomainError>> {
async getPendingSponsorshipRequests(input: { entityType: string; entityId: string }): Promise<Result<GetPendingSponsorshipRequestsOutputDTO, DomainError>> {
try {
const result = await this.apiClient.getPendingSponsorshipRequests(input);
return Result.ok(result);