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

@@ -3,9 +3,10 @@ import { UserId } from '../../domain/value-objects/UserId';
import { User } from '../../domain/entities/User';
import { IAuthRepository } from '../../domain/repositories/IAuthRepository';
import { IPasswordHashingService } from '../../domain/services/PasswordHashingService';
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 SignupInput = {
email: string;
@@ -26,15 +27,14 @@ export type SignupApplicationError = ApplicationErrorCode<SignupErrorCode, { mes
*
* Handles user registration.
*/
export class SignupUseCase implements UseCase<SignupInput, void, SignupErrorCode> {
export class SignupUseCase implements UseCase<SignupInput, SignupResult, SignupErrorCode> {
constructor(
private readonly authRepo: IAuthRepository,
private readonly passwordService: IPasswordHashingService,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<SignupResult>,
) {}
async execute(input: SignupInput): Promise<Result<void, SignupApplicationError>> {
async execute(input: SignupInput): Promise<Result<SignupResult, SignupApplicationError>> {
try {
// Validate email format
const emailVO = EmailAddress.create(input.email);
@@ -58,8 +58,7 @@ export class SignupUseCase implements UseCase<SignupInput, void, SignupErrorCode
// Hash password
const hashedPassword = await this.passwordService.hash(input.password);
const passwordHashModule = await import('../../domain/value-objects/PasswordHash');
const passwordHash = passwordHashModule.PasswordHash.fromHash(hashedPassword);
const passwordHash = PasswordHash.fromHash(hashedPassword);
// Create user (displayName validation happens in User entity constructor)
const userId = UserId.create();
@@ -72,8 +71,7 @@ export class SignupUseCase implements UseCase<SignupInput, void, SignupErrorCode
await this.authRepo.save(user);
this.output.present({ user });
return Result.ok(undefined);
return Result.ok({ user });
} catch (error) {
// Handle specific validation errors from User entity
if (error instanceof Error) {