refactor use cases
This commit is contained in:
@@ -2,7 +2,7 @@ import { User } from '../../domain/entities/User';
|
||||
import { IUserRepository } from '../../domain/repositories/IUserRepository';
|
||||
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';
|
||||
|
||||
export type GetCurrentSessionInput = {
|
||||
userId: string;
|
||||
@@ -28,11 +28,10 @@ export class GetCurrentSessionUseCase {
|
||||
constructor(
|
||||
private readonly userRepo: IUserRepository,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<GetCurrentSessionResult>,
|
||||
) {}
|
||||
|
||||
async execute(input: GetCurrentSessionInput): Promise<
|
||||
Result<void, GetCurrentSessionApplicationError>
|
||||
Result<GetCurrentSessionResult, GetCurrentSessionApplicationError>
|
||||
> {
|
||||
try {
|
||||
const stored = await this.userRepo.findById(input.userId);
|
||||
@@ -45,9 +44,8 @@ export class GetCurrentSessionUseCase {
|
||||
|
||||
const user = User.fromStored(stored);
|
||||
const result: GetCurrentSessionResult = { user };
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error && error.message
|
||||
@@ -66,4 +64,4 @@ export class GetCurrentSessionUseCase {
|
||||
} as GetCurrentSessionApplicationError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user