refactor use cases
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* Handles the business logic for updating a driver's avatar.
|
||||
*/
|
||||
|
||||
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';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
@@ -32,11 +32,10 @@ export type UpdateAvatarApplicationError = ApplicationErrorCode<
|
||||
export class UpdateAvatarUseCase {
|
||||
constructor(
|
||||
private readonly avatarRepo: IAvatarRepository,
|
||||
private readonly output: UseCaseOutputPort<UpdateAvatarResult>,
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
async execute(input: UpdateAvatarInput): Promise<Result<void, UpdateAvatarApplicationError>> {
|
||||
async execute(input: UpdateAvatarInput): Promise<Result<UpdateAvatarResult, UpdateAvatarApplicationError>> {
|
||||
this.logger.info('[UpdateAvatarUseCase] Updating avatar', {
|
||||
driverId: input.driverId,
|
||||
mediaUrl: input.mediaUrl,
|
||||
@@ -58,17 +57,15 @@ export class UpdateAvatarUseCase {
|
||||
|
||||
await this.avatarRepo.save(newAvatar);
|
||||
|
||||
this.output.present({
|
||||
avatarId: avatarId.toString(),
|
||||
driverId: input.driverId,
|
||||
});
|
||||
|
||||
this.logger.info('[UpdateAvatarUseCase] Avatar updated successfully', {
|
||||
driverId: input.driverId,
|
||||
avatarId: avatarId.toString(),
|
||||
});
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok({
|
||||
avatarId: avatarId.toString(),
|
||||
driverId: input.driverId,
|
||||
});
|
||||
} catch (error) {
|
||||
const err = error instanceof Error ? error : new Error(String(error));
|
||||
|
||||
@@ -76,7 +73,7 @@ export class UpdateAvatarUseCase {
|
||||
driverId: input.driverId,
|
||||
});
|
||||
|
||||
return Result.err({
|
||||
return Result.err<UpdateAvatarResult, UpdateAvatarApplicationError>({
|
||||
code: 'REPOSITORY_ERROR',
|
||||
details: { message: err.message ?? 'Internal error occurred while updating avatar' },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user