40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
/**
|
|
* 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' });
|
|
}
|
|
}
|
|
} |