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

@@ -7,7 +7,6 @@
import type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { UseCaseOutputPort } from '@core/shared/application';
import type { Sponsor } from '../../domain/entities/sponsor/Sponsor';
export type GetSponsorInput = {
@@ -23,10 +22,9 @@ export type GetSponsorErrorCode = 'SPONSOR_NOT_FOUND' | 'REPOSITORY_ERROR';
export class GetSponsorUseCase {
constructor(
private readonly sponsorRepository: ISponsorRepository,
private readonly output: UseCaseOutputPort<GetSponsorResult>,
) {}
async execute(input: GetSponsorInput): Promise<Result<void, ApplicationErrorCode<GetSponsorErrorCode, { message: string }>>> {
async execute(input: GetSponsorInput): Promise<Result<GetSponsorResult, ApplicationErrorCode<GetSponsorErrorCode, { message: string }>>> {
try {
const sponsor = await this.sponsorRepository.findById(input.sponsorId);
@@ -43,9 +41,7 @@ export class GetSponsorUseCase {
sponsor,
};
this.output.present(result);
return Result.ok(undefined);
return Result.ok(result);
} catch (error: unknown) {
const message =
error instanceof Error && typeof error.message === 'string'
@@ -60,4 +56,4 @@ export class GetSponsorUseCase {
});
}
}
}
}