refactor use cases
This commit is contained in:
@@ -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 {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user