30 lines
962 B
TypeScript
30 lines
962 B
TypeScript
/**
|
|
* 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 result = await authService.signup(params);
|
|
if (result.isErr()) {
|
|
return Result.err(result.getError().message);
|
|
}
|
|
return Result.ok(result.unwrap());
|
|
} catch (error: any) {
|
|
const errorMessage = error instanceof Error ? error.message : 'Signup failed';
|
|
return Result.err(errorMessage);
|
|
}
|
|
}
|
|
}
|