refactor use cases
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user