website refactor
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Forgot Password Page Query
|
||||
*
|
||||
* Composes data for the forgot password page using RSC pattern.
|
||||
* No business logic, only data composition.
|
||||
*/
|
||||
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { ForgotPasswordViewDataBuilder, ForgotPasswordViewData } from '@/lib/builders/view-data/ForgotPasswordViewDataBuilder';
|
||||
import { AuthPageService } from '@/lib/services/auth/AuthPageService';
|
||||
import { SearchParamParser } from '@/lib/routing/search-params/SearchParamParser';
|
||||
|
||||
export class ForgotPasswordPageQuery implements PageQuery<ForgotPasswordViewData, URLSearchParams> {
|
||||
async execute(searchParams: URLSearchParams): Promise<Result<ForgotPasswordViewData, string>> {
|
||||
// Parse and validate search parameters
|
||||
const parsedResult = SearchParamParser.parseAuth(searchParams);
|
||||
if (parsedResult.isErr()) {
|
||||
return Result.err(`Invalid search parameters: ${parsedResult.getError()}`);
|
||||
}
|
||||
|
||||
const { returnTo, token } = parsedResult.unwrap();
|
||||
|
||||
try {
|
||||
// Use service to process parameters
|
||||
const authService = new AuthPageService();
|
||||
const serviceResult = await authService.processForgotPasswordParams({ returnTo, token });
|
||||
|
||||
if (serviceResult.isErr()) {
|
||||
return Result.err(serviceResult.getError());
|
||||
}
|
||||
|
||||
// Transform to ViewData using builder
|
||||
const viewData = ForgotPasswordViewDataBuilder.build(serviceResult.unwrap());
|
||||
return Result.ok(viewData);
|
||||
} catch (error) {
|
||||
return Result.err('Failed to execute forgot password page query');
|
||||
}
|
||||
}
|
||||
|
||||
// Static factory method for convenience
|
||||
static async execute(searchParams: URLSearchParams): Promise<Result<ForgotPasswordViewData, string>> {
|
||||
const query = new ForgotPasswordPageQuery();
|
||||
return query.execute(searchParams);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user