website refactor
This commit is contained in:
26
apps/website/lib/mutations/auth/ForgotPasswordMutation.ts
Normal file
26
apps/website/lib/mutations/auth/ForgotPasswordMutation.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Forgot Password Mutation
|
||||
*
|
||||
* Framework-agnostic mutation for forgot password operations.
|
||||
* Called from Server Actions.
|
||||
*
|
||||
* Pattern: Server Action → Mutation → Service → API Client
|
||||
*/
|
||||
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { AuthService } from '@/lib/services/auth/AuthService';
|
||||
import { ForgotPasswordDTO } from '@/lib/types/generated/ForgotPasswordDTO';
|
||||
import { ForgotPasswordResult } from '@/lib/mutations/auth/types/ForgotPasswordResult';
|
||||
|
||||
export class ForgotPasswordMutation {
|
||||
async execute(params: ForgotPasswordDTO): Promise<Result<ForgotPasswordResult, string>> {
|
||||
try {
|
||||
const authService = new AuthService();
|
||||
const result = await authService.forgotPassword(params);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Failed to send reset link';
|
||||
return Result.err(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
26
apps/website/lib/mutations/auth/LoginMutation.ts
Normal file
26
apps/website/lib/mutations/auth/LoginMutation.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Login Mutation
|
||||
*
|
||||
* Framework-agnostic mutation for login operations.
|
||||
* Called from Server Actions.
|
||||
*
|
||||
* Pattern: Server Action → Mutation → Service → API Client
|
||||
*/
|
||||
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { AuthService } from '@/lib/services/auth/AuthService';
|
||||
import { SessionViewModel } from '@/lib/view-models/SessionViewModel';
|
||||
import { LoginParamsDTO } from '@/lib/types/generated/LoginParamsDTO';
|
||||
|
||||
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 errorMessage = error instanceof Error ? error.message : 'Login failed';
|
||||
return Result.err(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
26
apps/website/lib/mutations/auth/ResetPasswordMutation.ts
Normal file
26
apps/website/lib/mutations/auth/ResetPasswordMutation.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Reset Password Mutation
|
||||
*
|
||||
* Framework-agnostic mutation for reset password operations.
|
||||
* Called from Server Actions.
|
||||
*
|
||||
* Pattern: Server Action → Mutation → Service → API Client
|
||||
*/
|
||||
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { AuthService } from '@/lib/services/auth/AuthService';
|
||||
import { ResetPasswordDTO } from '@/lib/types/generated/ResetPasswordDTO';
|
||||
import { ResetPasswordResult } from '@/lib/mutations/auth/types/ResetPasswordResult';
|
||||
|
||||
export class ResetPasswordMutation {
|
||||
async execute(params: ResetPasswordDTO): Promise<Result<ResetPasswordResult, string>> {
|
||||
try {
|
||||
const authService = new AuthService();
|
||||
const result = await authService.resetPassword(params);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Failed to reset password';
|
||||
return Result.err(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
26
apps/website/lib/mutations/auth/SignupMutation.ts
Normal file
26
apps/website/lib/mutations/auth/SignupMutation.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Signup Mutation
|
||||
*
|
||||
* Framework-agnostic mutation for signup operations.
|
||||
* Called from Server Actions.
|
||||
*
|
||||
* Pattern: Server Action → Mutation → Service → API Client
|
||||
*/
|
||||
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { AuthService } from '@/lib/services/auth/AuthService';
|
||||
import { SessionViewModel } from '@/lib/view-models/SessionViewModel';
|
||||
import { SignupParamsDTO } from '@/lib/types/generated/SignupParamsDTO';
|
||||
|
||||
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 errorMessage = error instanceof Error ? error.message : 'Signup failed';
|
||||
return Result.err(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Forgot Password Mutation Result
|
||||
*
|
||||
* Result type for forgot password operations.
|
||||
* This represents the successful outcome of a forgot password mutation.
|
||||
*/
|
||||
|
||||
export interface ForgotPasswordResult {
|
||||
message: string;
|
||||
magicLink?: string;
|
||||
}
|
||||
10
apps/website/lib/mutations/auth/types/ResetPasswordResult.ts
Normal file
10
apps/website/lib/mutations/auth/types/ResetPasswordResult.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Reset Password Mutation Result
|
||||
*
|
||||
* Result type for reset password operations.
|
||||
* This represents the successful outcome of a reset password mutation.
|
||||
*/
|
||||
|
||||
export interface ResetPasswordResult {
|
||||
message: string;
|
||||
}
|
||||
Reference in New Issue
Block a user