website refactor
This commit is contained in:
@@ -15,7 +15,7 @@ import { Mutation } from '@/lib/contracts/mutations/Mutation';
|
||||
* Pattern: Server Action → Mutation → Service → API Client
|
||||
*/
|
||||
export class DeleteUserMutation implements Mutation<{ userId: string }, void, MutationError> {
|
||||
async execute(input: { userId: string }): Promise<Result<void, MutationError>> {
|
||||
async execute(_input: { userId: string }): Promise<Result<void, MutationError>> {
|
||||
try {
|
||||
// Manual construction: Service creates its own dependencies
|
||||
const service = new AdminService();
|
||||
|
||||
@@ -17,8 +17,11 @@ export class ForgotPasswordMutation {
|
||||
try {
|
||||
const authService = new AuthService();
|
||||
const result = await authService.forgotPassword(params);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
if (result.isErr()) {
|
||||
return Result.err(result.getError().message);
|
||||
}
|
||||
return Result.ok(result.unwrap());
|
||||
} catch (error: any) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Failed to send reset link';
|
||||
return Result.err(errorMessage);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,12 @@ export class LoginMutation {
|
||||
async execute(params: LoginParamsDTO): Promise<Result<SessionViewModel, string>> {
|
||||
try {
|
||||
const authService = new AuthService();
|
||||
const session = await authService.login(params);
|
||||
return Result.ok(session);
|
||||
} catch (error) {
|
||||
const result = await authService.login(params);
|
||||
if (result.isErr()) {
|
||||
return Result.err(result.getError().message);
|
||||
}
|
||||
return Result.ok(new SessionViewModel(result.unwrap().user));
|
||||
} catch (error: any) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Login failed';
|
||||
return Result.err(errorMessage);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,11 @@ export class ResetPasswordMutation {
|
||||
try {
|
||||
const authService = new AuthService();
|
||||
const result = await authService.resetPassword(params);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
if (result.isErr()) {
|
||||
return Result.err(result.getError().message);
|
||||
}
|
||||
return Result.ok(result.unwrap());
|
||||
} catch (error: any) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Failed to reset password';
|
||||
return Result.err(errorMessage);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,12 @@ export class SignupMutation {
|
||||
async execute(params: SignupParamsDTO): Promise<Result<SessionViewModel, string>> {
|
||||
try {
|
||||
const authService = new AuthService();
|
||||
const session = await authService.signup(params);
|
||||
return Result.ok(session);
|
||||
} catch (error) {
|
||||
const result = await authService.signup(params);
|
||||
if (result.isErr()) {
|
||||
return Result.err(result.getError().message);
|
||||
}
|
||||
return Result.ok(new SessionViewModel(result.unwrap().user));
|
||||
} catch (error: any) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Signup failed';
|
||||
return Result.err(errorMessage);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export interface UpdateDriverProfileCommand {
|
||||
|
||||
type UpdateDriverProfileMutationError = 'DRIVER_PROFILE_UPDATE_FAILED';
|
||||
|
||||
const mapToMutationError = (_error: DomainError): UpdateDriverProfileMutationError => {
|
||||
const mapToMutationError = (_: DomainError): UpdateDriverProfileMutationError => {
|
||||
return 'DRIVER_PROFILE_UPDATE_FAILED';
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { LeagueService } from '@/lib/services/leagues/LeagueService';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import type { CreateLeagueInputDTO } from '@/lib/types/generated/CreateLeagueInputDTO';
|
||||
import { DomainError } from '@/lib/contracts/services/Service';
|
||||
|
||||
/**
|
||||
* CreateLeagueMutation
|
||||
@@ -15,22 +13,19 @@ export class CreateLeagueMutation {
|
||||
private service: LeagueService;
|
||||
|
||||
constructor() {
|
||||
// Manual wiring for serverless
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
this.service = new LeagueService();
|
||||
}
|
||||
|
||||
async execute(input: CreateLeagueInputDTO): Promise<Result<string, string>> {
|
||||
async execute(input: CreateLeagueInputDTO): Promise<Result<string, DomainError>> {
|
||||
try {
|
||||
const result = await this.service.createLeague(input);
|
||||
return Result.ok(result.leagueId);
|
||||
} catch (error) {
|
||||
if (result.isErr()) {
|
||||
return Result.err(result.getError());
|
||||
}
|
||||
return Result.ok(result.unwrap().leagueId);
|
||||
} catch (error: any) {
|
||||
console.error('CreateLeagueMutation failed:', error);
|
||||
return Result.err('Failed to create league');
|
||||
return Result.err({ type: 'serverError', message: error.message || 'Failed to create league' });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { ProtestService } from '@/lib/services/protests/ProtestService';
|
||||
import { ProtestsApiClient } from '@/lib/api/protests/ProtestsApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import type { ApplyPenaltyCommandDTO } from '@/lib/types/generated/ApplyPenaltyCommandDTO';
|
||||
import type { RequestProtestDefenseCommandDTO } from '@/lib/types/generated/RequestProtestDefenseCommandDTO';
|
||||
import { DomainError } from '@/lib/contracts/services/Service';
|
||||
|
||||
/**
|
||||
* ProtestReviewMutation
|
||||
@@ -16,42 +14,34 @@ export class ProtestReviewMutation {
|
||||
private service: ProtestService;
|
||||
|
||||
constructor() {
|
||||
// Manual wiring for serverless
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new ProtestsApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
this.service = new ProtestService(apiClient);
|
||||
this.service = new ProtestService();
|
||||
}
|
||||
|
||||
async applyPenalty(input: ApplyPenaltyCommandDTO): Promise<Result<void, string>> {
|
||||
async applyPenalty(input: ApplyPenaltyCommandDTO): Promise<Result<void, DomainError>> {
|
||||
try {
|
||||
await this.service.applyPenalty(input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
return await this.service.applyPenalty(input);
|
||||
} catch (error: unknown) {
|
||||
console.error('applyPenalty failed:', error);
|
||||
return Result.err('Failed to apply penalty');
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to apply penalty' });
|
||||
}
|
||||
}
|
||||
|
||||
async requestDefense(input: RequestProtestDefenseCommandDTO): Promise<Result<void, string>> {
|
||||
async requestDefense(input: RequestProtestDefenseCommandDTO): Promise<Result<void, DomainError>> {
|
||||
try {
|
||||
await this.service.requestDefense(input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
return await this.service.requestDefense(input);
|
||||
} catch (error: unknown) {
|
||||
console.error('requestDefense failed:', error);
|
||||
return Result.err('Failed to request defense');
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to request defense' });
|
||||
}
|
||||
}
|
||||
|
||||
async reviewProtest(input: { protestId: string; stewardId: string; decision: string; decisionNotes: string }): Promise<Result<void, string>> {
|
||||
async reviewProtest(input: { protestId: string; stewardId: string; decision: string; decisionNotes: string }): Promise<Result<void, DomainError>> {
|
||||
try {
|
||||
await this.service.reviewProtest(input as any);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return await this.service.reviewProtest(input as any);
|
||||
} catch (error: unknown) {
|
||||
console.error('reviewProtest failed:', error);
|
||||
return Result.err('Failed to review protest');
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to review protest' });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export class RosterAdminMutation {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
this.service = new LeagueService();
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ import { LeagueService } from '@/lib/services/leagues/LeagueService';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import type { CreateLeagueScheduleRaceInputDTO } from '@/lib/types/generated/CreateLeagueScheduleRaceInputDTO';
|
||||
import type { UpdateLeagueScheduleRaceInputDTO } from '@/lib/types/generated/UpdateLeagueScheduleRaceInputDTO';
|
||||
|
||||
/**
|
||||
* ScheduleAdminMutation
|
||||
@@ -20,7 +18,7 @@ export class ScheduleAdminMutation {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
this.service = new LeagueService();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export class StewardingMutation {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
this.service = new LeagueService();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export class WalletMutation {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
this.service = new LeagueService();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user