refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -5,7 +5,7 @@ import { EmailAddress } from '../../domain/value-objects/EmailAddress';
import { PasswordHash } from '../../domain/value-objects/PasswordHash';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { UseCaseOutputPort, Logger, UseCase } from '@core/shared/application';
import type { Logger, UseCase } from '@core/shared/application';
export type ResetPasswordInput = {
token: string;
@@ -26,16 +26,15 @@ export type ResetPasswordApplicationError = ApplicationErrorCode<ResetPasswordEr
* Handles password reset using a magic link token.
* Validates token, checks expiration, and updates password.
*/
export class ResetPasswordUseCase implements UseCase<ResetPasswordInput, void, ResetPasswordErrorCode> {
export class ResetPasswordUseCase implements UseCase<ResetPasswordInput, ResetPasswordResult, ResetPasswordErrorCode> {
constructor(
private readonly authRepo: IAuthRepository,
private readonly magicLinkRepo: IMagicLinkRepository,
private readonly passwordService: IPasswordHashingService,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<ResetPasswordResult>,
) {}
async execute(input: ResetPasswordInput): Promise<Result<void, ResetPasswordApplicationError>> {
async execute(input: ResetPasswordInput): Promise<Result<ResetPasswordResult, ResetPasswordApplicationError>> {
try {
// Validate token format
if (!input.token || typeof input.token !== 'string' || input.token.length < 32) {
@@ -111,11 +110,9 @@ export class ResetPasswordUseCase implements UseCase<ResetPasswordInput, void, R
email: resetRequest.email,
});
this.output.present({
return Result.ok({
message: 'Password reset successfully. You can now log in with your new password.',
});
return Result.ok(undefined);
} catch (error) {
const message =
error instanceof Error && error.message