refactor use cases
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import type { IAvatarRepository } from '../../domain/repositories/IAvatarRepository';
|
||||
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
@@ -32,11 +32,10 @@ export type GetAvatarApplicationError = ApplicationErrorCode<
|
||||
export class GetAvatarUseCase {
|
||||
constructor(
|
||||
private readonly avatarRepo: IAvatarRepository,
|
||||
private readonly output: UseCaseOutputPort<GetAvatarResult>,
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
async execute(input: GetAvatarInput): Promise<Result<void, GetAvatarApplicationError>> {
|
||||
async execute(input: GetAvatarInput): Promise<Result<GetAvatarResult, GetAvatarApplicationError>> {
|
||||
this.logger.info('[GetAvatarUseCase] Getting avatar', {
|
||||
driverId: input.driverId,
|
||||
});
|
||||
@@ -45,13 +44,13 @@ export class GetAvatarUseCase {
|
||||
const avatar = await this.avatarRepo.findActiveByDriverId(input.driverId);
|
||||
|
||||
if (!avatar) {
|
||||
return Result.err({
|
||||
return Result.err<GetAvatarResult, GetAvatarApplicationError>({
|
||||
code: 'AVATAR_NOT_FOUND',
|
||||
details: { message: 'Avatar not found' },
|
||||
});
|
||||
}
|
||||
|
||||
this.output.present({
|
||||
return Result.ok({
|
||||
avatar: {
|
||||
id: avatar.id,
|
||||
driverId: avatar.driverId,
|
||||
@@ -59,8 +58,6 @@ export class GetAvatarUseCase {
|
||||
selectedAt: avatar.selectedAt,
|
||||
},
|
||||
});
|
||||
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
const err = error instanceof Error ? error : new Error(String(error));
|
||||
|
||||
@@ -68,7 +65,7 @@ export class GetAvatarUseCase {
|
||||
driverId: input.driverId,
|
||||
});
|
||||
|
||||
return Result.err({
|
||||
return Result.err<GetAvatarResult, GetAvatarApplicationError>({
|
||||
code: 'REPOSITORY_ERROR',
|
||||
details: { message: err.message ?? 'Unexpected repository error' },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user