resolve manual DTOs
This commit is contained in:
40
core/racing/application/use-cases/GetSponsorUseCase.ts
Normal file
40
core/racing/application/use-cases/GetSponsorUseCase.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Application Use Case: GetSponsorUseCase
|
||||
*
|
||||
* Retrieves a single sponsor by ID.
|
||||
*/
|
||||
|
||||
import type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
export interface GetSponsorQueryParams {
|
||||
sponsorId: string;
|
||||
}
|
||||
|
||||
export class GetSponsorUseCase {
|
||||
constructor(
|
||||
private readonly sponsorRepository: ISponsorRepository,
|
||||
) {}
|
||||
|
||||
async execute(params: GetSponsorQueryParams): Promise<Result<{ sponsor: { id: string; name: string; logoUrl?: string; websiteUrl?: string } } | null, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
|
||||
try {
|
||||
const sponsor = await this.sponsorRepository.findById(params.sponsorId);
|
||||
|
||||
if (!sponsor) {
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
const sponsorData = {
|
||||
id: sponsor.id,
|
||||
name: sponsor.name,
|
||||
logoUrl: sponsor.logoUrl,
|
||||
websiteUrl: sponsor.websiteUrl,
|
||||
};
|
||||
|
||||
return Result.ok({ sponsor: sponsorData });
|
||||
} catch {
|
||||
return Result.err({ code: 'REPOSITORY_ERROR', message: 'Failed to fetch sponsor' });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user