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

@@ -4,7 +4,7 @@ import { IAuthRepository } from '../../domain/repositories/IAuthRepository';
import { IPasswordHashingService } from '../../domain/services/PasswordHashingService';
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 LoginInput = {
email: string;
@@ -24,15 +24,14 @@ export type LoginApplicationError = ApplicationErrorCode<LoginErrorCode, { messa
*
* Handles user login by verifying credentials.
*/
export class LoginUseCase implements UseCase<LoginInput, void, LoginErrorCode> {
export class LoginUseCase implements UseCase<LoginInput, LoginResult, LoginErrorCode> {
constructor(
private readonly authRepo: IAuthRepository,
private readonly passwordService: IPasswordHashingService,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<LoginResult>,
) {}
async execute(input: LoginInput): Promise<Result<void, LoginApplicationError>> {
async execute(input: LoginInput): Promise<Result<LoginResult, LoginApplicationError>> {
try {
const emailVO = EmailAddress.create(input.email);
const user = await this.authRepo.findByEmail(emailVO);
@@ -48,14 +47,13 @@ export class LoginUseCase implements UseCase<LoginInput, void, LoginErrorCode> {
const isValid = await this.passwordService.verify(input.password, passwordHash.value);
if (!isValid) {
return Result.err<void, LoginApplicationError>({
return Result.err<LoginResult, LoginApplicationError>({
code: 'INVALID_CREDENTIALS',
details: { message: 'Invalid credentials' },
});
}
this.output.present({ user });
return Result.ok(undefined);
return Result.ok({ user });
} catch (error) {
const message =
error instanceof Error && error.message
@@ -66,7 +64,7 @@ export class LoginUseCase implements UseCase<LoginInput, void, LoginErrorCode> {
input,
});
return Result.err<void, LoginApplicationError>({
return Result.err<LoginResult, LoginApplicationError>({
code: 'REPOSITORY_ERROR',
details: { message },
});