refactor racing use cases
This commit is contained in:
@@ -4,24 +4,57 @@
|
||||
* Retrieves general sponsorship pricing tiers.
|
||||
*/
|
||||
|
||||
import type { GetSponsorshipPricingOutputPort } from '../ports/output/GetSponsorshipPricingOutputPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
export type GetSponsorshipPricingInput = Record<string, never>;
|
||||
|
||||
export type GetSponsorshipPricingResult = {
|
||||
entityType: 'season';
|
||||
entityId: string;
|
||||
pricing: {
|
||||
id: string;
|
||||
level: string;
|
||||
price: number;
|
||||
currency: string;
|
||||
}[];
|
||||
};
|
||||
|
||||
export type GetSponsorshipPricingErrorCode = 'REPOSITORY_ERROR';
|
||||
|
||||
export class GetSponsorshipPricingUseCase {
|
||||
constructor() {}
|
||||
constructor(private readonly output: UseCaseOutputPort<GetSponsorshipPricingResult>) {}
|
||||
|
||||
async execute(): Promise<Result<GetSponsorshipPricingOutputPort, ApplicationErrorCode<'NO_ERROR'>>> {
|
||||
const outputPort: GetSponsorshipPricingOutputPort = {
|
||||
entityType: 'season',
|
||||
entityId: '',
|
||||
pricing: [
|
||||
{ id: 'tier-bronze', level: 'Bronze', price: 100, currency: 'USD' },
|
||||
{ id: 'tier-silver', level: 'Silver', price: 250, currency: 'USD' },
|
||||
{ id: 'tier-gold', level: 'Gold', price: 500, currency: 'USD' },
|
||||
],
|
||||
};
|
||||
async execute(
|
||||
_input: GetSponsorshipPricingInput,
|
||||
): Promise<
|
||||
Result<void, ApplicationErrorCode<GetSponsorshipPricingErrorCode, { message: string }>>
|
||||
> {
|
||||
try {
|
||||
const result: GetSponsorshipPricingResult = {
|
||||
entityType: 'season',
|
||||
entityId: '',
|
||||
pricing: [
|
||||
{ id: 'tier-bronze', level: 'Bronze', price: 100, currency: 'USD' },
|
||||
{ id: 'tier-silver', level: 'Silver', price: 250, currency: 'USD' },
|
||||
{ id: 'tier-gold', level: 'Gold', price: 500, currency: 'USD' },
|
||||
],
|
||||
};
|
||||
|
||||
return Result.ok(outputPort);
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
return Result.err({
|
||||
code: 'REPOSITORY_ERROR',
|
||||
details: {
|
||||
message:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: 'Failed to load sponsorship pricing',
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user