website refactor

This commit is contained in:
2026-01-16 01:00:03 +01:00
parent ce7be39155
commit a98e3e3166
286 changed files with 5522 additions and 5261 deletions

View File

@@ -42,8 +42,8 @@ export class SponsorService implements Service {
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' });
} catch (error: unknown) {
return Result.err({ type: 'unknown', message: (error as Error).message || 'Failed to get sponsor' });
}
}
@@ -54,8 +54,8 @@ export class SponsorService implements Service {
return Result.err({ type: 'notFound', message: 'Dashboard not found' });
}
return Result.ok(result);
} catch (error) {
return Result.err({ type: 'notImplemented', message: 'getSponsorDashboard' });
} catch (error: unknown) {
return Result.err({ type: 'notImplemented', message: (error as Error).message || 'getSponsorDashboard' });
}
}
@@ -66,12 +66,12 @@ export class SponsorService implements Service {
return Result.err({ type: 'notFound', message: 'Sponsorships not found' });
}
return Result.ok(result);
} catch (error) {
return Result.err({ type: 'notImplemented', message: 'getSponsorSponsorships' });
} catch (error: unknown) {
return Result.err({ type: 'notImplemented', message: (error as Error).message || 'getSponsorSponsorships' });
}
}
async getBilling(): Promise<Result<SponsorBillingDTO, DomainError>> {
async getBilling(_: string): Promise<Result<SponsorBillingDTO, DomainError>> {
return Result.err({ type: 'notImplemented', message: 'getBilling' });
}
@@ -95,8 +95,8 @@ export class SponsorService implements Service {
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' });
} catch (error: unknown) {
return Result.err({ type: 'unknown', message: (error as Error).message || 'Failed to accept sponsorship request' });
}
}
@@ -104,8 +104,8 @@ export class SponsorService implements Service {
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' });
} catch (error: unknown) {
return Result.err({ type: 'unknown', message: (error as Error).message || 'Failed to reject sponsorship request' });
}
}
@@ -113,8 +113,8 @@ export class SponsorService implements Service {
try {
const result = await this.apiClient.getPendingSponsorshipRequests(input);
return Result.ok(result);
} catch (error) {
return Result.err({ type: 'notImplemented', message: 'getPendingSponsorshipRequests' });
} catch (error: unknown) {
return Result.err({ type: 'notImplemented', message: (error as Error).message || 'getPendingSponsorshipRequests' });
}
}
}
}

View File

@@ -2,7 +2,7 @@ import { SponsorsApiClient } from '@/lib/api/sponsors/SponsorsApiClient';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
import { isProductionEnvironment } from '@/lib/config/env';
import { Result } from '@/lib/contracts/Result';
import type { Service } from '@/lib/contracts/services/Service';
import type { Service, DomainError } from '@/lib/contracts/services/Service';
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
@@ -23,8 +23,6 @@ export interface SponsorshipRequestsReadApiDto {
}>;
}
export type SponsorshipRequestsReadServiceError = 'notFound' | 'unauthorized' | 'serverError';
export class SponsorshipRequestsReadService implements Service {
private readonly client: SponsorsApiClient;
@@ -42,7 +40,7 @@ export class SponsorshipRequestsReadService implements Service {
async getPendingRequestsForDriver(
driverId: string,
): Promise<Result<SponsorshipRequestsReadApiDto, SponsorshipRequestsReadServiceError>> {
): Promise<Result<SponsorshipRequestsReadApiDto, DomainError>> {
try {
const response = await this.client.getPendingSponsorshipRequests({
entityType: 'driver',
@@ -79,11 +77,11 @@ export class SponsorshipRequestsReadService implements Service {
},
],
});
} catch (error) {
} catch (error: any) {
const errorAny = error as { statusCode?: number; message?: string };
if (errorAny.statusCode === 401) return Result.err('unauthorized');
if (errorAny.statusCode === 404) return Result.err('notFound');
return Result.err('serverError');
if (errorAny.statusCode === 401) return Result.err({ type: 'unauthorized', message: 'Unauthorized' });
if (errorAny.statusCode === 404) return Result.err({ type: 'notFound', message: 'Not found' });
return Result.err({ type: 'serverError', message: error.message || 'Server error' });
}
}
}

View File

@@ -2,7 +2,7 @@ import { SponsorsApiClient } from '@/lib/api/sponsors/SponsorsApiClient';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
import { isProductionEnvironment } from '@/lib/config/env';
import { Result } from '@/lib/contracts/Result';
import type { Service } from '@/lib/contracts/services/Service';
import { Service, DomainError } from '@/lib/contracts/services/Service';
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
import type { GetPendingSponsorshipRequestsOutputDTO } from '@/lib/types/generated/GetPendingSponsorshipRequestsOutputDTO';
@@ -31,7 +31,7 @@ export class SponsorshipRequestsService implements Service {
async getPendingRequests(
input: GetPendingRequestsInput,
): Promise<Result<GetPendingSponsorshipRequestsOutputDTO, 'GET_PENDING_REQUESTS_FAILED'>> {
): Promise<Result<GetPendingSponsorshipRequestsOutputDTO, DomainError>> {
try {
const result = await this.client.getPendingSponsorshipRequests({
entityType: input.entityType,
@@ -40,13 +40,13 @@ export class SponsorshipRequestsService implements Service {
return Result.ok(result);
} catch {
return Result.err('GET_PENDING_REQUESTS_FAILED');
return Result.err({ type: 'serverError', message: 'Failed to fetch pending requests' });
}
}
async acceptRequest(
command: { requestId: string; actorDriverId: string },
): Promise<Result<void, 'ACCEPT_SPONSORSHIP_REQUEST_FAILED'>> {
): Promise<Result<void, DomainError>> {
try {
const input: AcceptSponsorshipRequestInputDTO = {
respondedBy: command.actorDriverId,
@@ -55,13 +55,13 @@ export class SponsorshipRequestsService implements Service {
return Result.ok(undefined);
} catch {
return Result.err('ACCEPT_SPONSORSHIP_REQUEST_FAILED');
return Result.err({ type: 'serverError', message: 'Failed to accept sponsorship request' });
}
}
async rejectRequest(
command: { requestId: string; actorDriverId: string; reason: string | null },
): Promise<Result<void, 'REJECT_SPONSORSHIP_REQUEST_FAILED'>> {
): Promise<Result<void, DomainError>> {
try {
const input: RejectSponsorshipRequestInputDTO = {
respondedBy: command.actorDriverId,
@@ -71,7 +71,7 @@ export class SponsorshipRequestsService implements Service {
return Result.ok(undefined);
} catch {
return Result.err('REJECT_SPONSORSHIP_REQUEST_FAILED');
return Result.err({ type: 'serverError', message: 'Failed to reject sponsorship request' });
}
}
}