view data fixes
This commit is contained in:
@@ -1,30 +1,52 @@
|
||||
/**
|
||||
* Complete Onboarding Mutation
|
||||
*
|
||||
* Framework-agnostic mutation for completing onboarding.
|
||||
* Called from Server Actions.
|
||||
*
|
||||
* Pattern: Server Action → Mutation → Service → API Client
|
||||
*/
|
||||
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { Mutation } from '@/lib/contracts/mutations/Mutation';
|
||||
import { mapToMutationError } from '@/lib/contracts/mutations/MutationError';
|
||||
import { OnboardingService } from '@/lib/services/onboarding/OnboardingService';
|
||||
import { CompleteOnboardingInputDTO } from '@/lib/types/generated/CompleteOnboardingInputDTO';
|
||||
import { CompleteOnboardingViewDataBuilder } from '@/lib/builders/view-data/CompleteOnboardingViewDataBuilder';
|
||||
import { CompleteOnboardingViewData } from '@/lib/builders/view-data/CompleteOnboardingViewData';
|
||||
import type { Mutation } from '@/lib/contracts/mutations/Mutation';
|
||||
|
||||
export class CompleteOnboardingMutation implements Mutation<CompleteOnboardingInputDTO, CompleteOnboardingViewData, string> {
|
||||
async execute(params: CompleteOnboardingInputDTO): Promise<Result<CompleteOnboardingViewData, string>> {
|
||||
const onboardingService = new OnboardingService();
|
||||
const result = await onboardingService.completeOnboarding(params);
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err(mapToMutationError(result.getError()));
|
||||
}
|
||||
|
||||
const output = CompleteOnboardingViewDataBuilder.build(result.unwrap());
|
||||
return Result.ok(output);
|
||||
export interface CompleteOnboardingCommand {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
displayName: string;
|
||||
country: string;
|
||||
timezone?: string;
|
||||
bio?: string;
|
||||
}
|
||||
|
||||
export type CompleteOnboardingMutationError = 'onboardingFailed';
|
||||
|
||||
export class CompleteOnboardingMutation
|
||||
implements
|
||||
Mutation<
|
||||
CompleteOnboardingCommand,
|
||||
void,
|
||||
CompleteOnboardingMutationError
|
||||
>
|
||||
{
|
||||
private readonly service: OnboardingService;
|
||||
|
||||
constructor() {
|
||||
this.service = new OnboardingService();
|
||||
}
|
||||
}
|
||||
|
||||
async execute(
|
||||
command: CompleteOnboardingCommand,
|
||||
): Promise<Result<void, CompleteOnboardingMutationError>> {
|
||||
try {
|
||||
const result = await this.service.completeOnboarding({
|
||||
firstName: command.firstName,
|
||||
lastName: command.lastName,
|
||||
displayName: command.displayName,
|
||||
country: command.country,
|
||||
timezone: command.timezone,
|
||||
bio: command.bio,
|
||||
});
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err('onboardingFailed');
|
||||
}
|
||||
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
return Result.err('onboardingFailed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user