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

@@ -4,6 +4,11 @@ import type { GetDriverOutputDTO } from '@/lib/types/generated/GetDriverOutputDT
import type { CompleteOnboardingOutputDTO } from '@/lib/types/generated/CompleteOnboardingOutputDTO';
import type { DriverDTO } from '@/lib/types/generated/DriverDTO';
import type { GetDriverProfileOutputDTO } from '@/lib/types/generated/GetDriverProfileOutputDTO';
import { Result } from '@/lib/contracts/Result';
import { DomainError, Service } from '@/lib/contracts/services/Service';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
/**
* Driver Service - DTO Only
@@ -11,58 +16,97 @@ import type { GetDriverProfileOutputDTO } from '@/lib/types/generated/GetDriverP
* Returns raw API DTOs. No ViewModels or UX logic.
* All client-side presentation logic must be handled by hooks/components.
*/
export class DriverService {
constructor(
private readonly apiClient: DriversApiClient
) {}
export class DriverService implements Service {
private readonly apiClient: DriversApiClient;
constructor() {
const baseUrl = getWebsiteApiBaseUrl();
const logger = new ConsoleLogger();
const errorReporter = new EnhancedErrorReporter(logger);
this.apiClient = new DriversApiClient(baseUrl, errorReporter, logger);
}
/**
* Get driver leaderboard (returns DTO)
*/
async getDriverLeaderboard() {
return this.apiClient.getLeaderboard();
async getDriverLeaderboard(): Promise<Result<unknown, DomainError>> {
try {
const data = await this.apiClient.getLeaderboard();
return Result.ok(data);
} catch (error: unknown) {
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to get leaderboard' });
}
}
/**
* Complete driver onboarding (returns DTO)
*/
async completeDriverOnboarding(input: CompleteOnboardingInputDTO): Promise<CompleteOnboardingOutputDTO> {
return this.apiClient.completeOnboarding(input);
async completeDriverOnboarding(input: CompleteOnboardingInputDTO): Promise<Result<CompleteOnboardingOutputDTO, DomainError>> {
try {
const data = await this.apiClient.completeOnboarding(input);
return Result.ok(data);
} catch (error: unknown) {
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to complete onboarding' });
}
}
/**
* Get current driver (returns DTO)
*/
async getCurrentDriver(): Promise<DriverDTO | null> {
return this.apiClient.getCurrent();
async getCurrentDriver(): Promise<Result<DriverDTO | null, DomainError>> {
try {
const data = await this.apiClient.getCurrent();
return Result.ok(data);
} catch (error: unknown) {
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to get current driver' });
}
}
/**
* Get driver profile (returns DTO)
*/
async getDriverProfile(driverId: string): Promise<GetDriverProfileOutputDTO> {
return this.apiClient.getDriverProfile(driverId);
async getDriverProfile(driverId: string): Promise<Result<GetDriverProfileOutputDTO, DomainError>> {
try {
const data = await this.apiClient.getDriverProfile(driverId);
return Result.ok(data);
} catch (error: unknown) {
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to get driver profile' });
}
}
/**
* Update current driver profile (returns DTO)
*/
async updateProfile(updates: { bio?: string; country?: string }): Promise<DriverDTO> {
return this.apiClient.updateProfile(updates);
async updateProfile(updates: { bio?: string; country?: string }): Promise<Result<DriverDTO, DomainError>> {
try {
const data = await this.apiClient.updateProfile(updates);
return Result.ok(data);
} catch (error: unknown) {
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to update profile' });
}
}
/**
* Find driver by ID (returns DTO)
*/
async findById(id: string): Promise<GetDriverOutputDTO | null> {
return this.apiClient.getDriver(id);
async findById(id: string): Promise<Result<GetDriverOutputDTO | null, DomainError>> {
try {
const data = await this.apiClient.getDriver(id);
return Result.ok(data);
} catch (error: unknown) {
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to find driver' });
}
}
/**
* Find multiple drivers by IDs (returns DTOs)
*/
async findByIds(ids: string[]): Promise<GetDriverOutputDTO[]> {
const drivers = await Promise.all(ids.map(id => this.apiClient.getDriver(id)));
return drivers.filter((d): d is GetDriverOutputDTO => d !== null);
async findByIds(ids: string[]): Promise<Result<GetDriverOutputDTO[], DomainError>> {
try {
const drivers = await Promise.all(ids.map(id => this.apiClient.getDriver(id)));
return Result.ok(drivers.filter((d): d is GetDriverOutputDTO => d !== null));
} catch (error: unknown) {
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to find drivers' });
}
}
}