refactor racing use cases
This commit is contained in:
@@ -5,31 +5,28 @@
|
||||
*/
|
||||
|
||||
import type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository';
|
||||
import type { GetSponsorsOutputPort } from '../ports/output/GetSponsorsOutputPort';
|
||||
import type { Sponsor } from '../../domain/entities/sponsor/Sponsor';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
type GetSponsorsResult = {
|
||||
sponsors: Sponsor[];
|
||||
};
|
||||
|
||||
export class GetSponsorsUseCase {
|
||||
constructor(
|
||||
private readonly sponsorRepository: ISponsorRepository,
|
||||
private readonly output: UseCaseOutputPort<GetSponsorsResult>,
|
||||
) {}
|
||||
|
||||
async execute(): Promise<Result<GetSponsorsOutputPort, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
|
||||
async execute(): Promise<Result<void, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
|
||||
try {
|
||||
const sponsors = await this.sponsorRepository.findAll();
|
||||
|
||||
const outputPort: GetSponsorsOutputPort = {
|
||||
sponsors: sponsors.map(sponsor => ({
|
||||
id: sponsor.id,
|
||||
name: sponsor.name,
|
||||
contactEmail: sponsor.contactEmail,
|
||||
websiteUrl: sponsor.websiteUrl,
|
||||
logoUrl: sponsor.logoUrl,
|
||||
createdAt: sponsor.createdAt,
|
||||
})),
|
||||
};
|
||||
this.output.present({ sponsors });
|
||||
|
||||
return Result.ok(outputPort);
|
||||
return Result.ok(undefined);
|
||||
} catch {
|
||||
return Result.err({ code: 'REPOSITORY_ERROR', message: 'Failed to fetch sponsors' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user