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

@@ -1,11 +1,9 @@
import { ApiClient } from '@/lib/api';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
import { Result } from '@/lib/contracts/Result';
import type { Service } from '@/lib/contracts/services/Service';
import { Service, type DomainError } from '@/lib/contracts/services/Service';
type ProfileLeaguesServiceError = 'notFound' | 'redirect' | 'unknown';
interface ProfileLeaguesPageDto {
export interface ProfileLeaguesPageDto {
ownedLeagues: Array<{
leagueId: string;
name: string;
@@ -27,7 +25,7 @@ interface MembershipDTO {
}
export class ProfileLeaguesService implements Service {
async getProfileLeagues(driverId: string): Promise<Result<ProfileLeaguesPageDto, ProfileLeaguesServiceError>> {
async getProfileLeagues(driverId: string): Promise<Result<ProfileLeaguesPageDto, DomainError>> {
try {
const baseUrl = getWebsiteApiBaseUrl();
const apiClient = new ApiClient(baseUrl);
@@ -35,7 +33,7 @@ export class ProfileLeaguesService implements Service {
const leaguesDto = await apiClient.leagues.getAllWithCapacity();
if (!leaguesDto?.leagues) {
return Result.err('notFound');
return Result.err({ type: 'notFound', message: 'Leagues not found' });
}
// Fetch all memberships in parallel
@@ -80,18 +78,18 @@ export class ProfileLeaguesService implements Service {
ownedLeagues,
memberLeagues,
});
} catch (error) {
} catch (error: any) {
const errorAny = error as { statusCode?: number; message?: string };
if (errorAny.statusCode === 404 || errorAny.message?.toLowerCase().includes('not found')) {
return Result.err('notFound');
return Result.err({ type: 'notFound', message: 'Profile leagues not found' });
}
if (errorAny.statusCode === 302 || errorAny.message?.toLowerCase().includes('redirect')) {
return Result.err('redirect');
return Result.err({ type: 'unauthorized', message: 'Unauthorized access' });
}
return Result.err('unknown');
return Result.err({ type: 'unknown', message: error.message || 'Failed to fetch profile leagues' });
}
}
}