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

@@ -8,7 +8,8 @@ import type { IUserRepository } from '../../domain/repositories/IUserRepository'
import type { IdentitySessionPort } from '../ports/IdentitySessionPort';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { UseCaseOutputPort, Logger } from '@core/shared/application';
import type { Logger } from '@core/shared/application';
import { PasswordHash } from '@core/identity/domain/value-objects/PasswordHash';
export type LoginWithEmailInput = {
email: string;
@@ -40,10 +41,9 @@ export class LoginWithEmailUseCase {
private readonly userRepository: IUserRepository,
private readonly sessionPort: IdentitySessionPort,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<LoginWithEmailResult>,
) {}
async execute(input: LoginWithEmailInput): Promise<Result<void, LoginWithEmailApplicationError>> {
async execute(input: LoginWithEmailInput): Promise<Result<LoginWithEmailResult, LoginWithEmailApplicationError>> {
try {
if (!input.email || !input.password) {
return Result.err({
@@ -63,7 +63,6 @@ export class LoginWithEmailUseCase {
}
// Verify password using PasswordHash value object
const { PasswordHash } = await import('@core/identity/domain/value-objects/PasswordHash');
const storedPasswordHash = PasswordHash.fromHash(user.passwordHash);
const isValid = await storedPasswordHash.verify(input.password);
@@ -99,9 +98,7 @@ export class LoginWithEmailUseCase {
expiresAt: session.expiresAt,
};
this.output.present(result);
return Result.ok(undefined);
return Result.ok(result);
} catch (error) {
const message =
error instanceof Error && error.message