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

@@ -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' },
});