This commit is contained in:
2025-12-21 17:05:36 +01:00
parent 08b0d59e45
commit f2d8a23583
66 changed files with 1131 additions and 1342 deletions

View File

@@ -5,14 +5,12 @@
*/
import type { IPaymentRepository } from '../../domain/repositories/IPaymentRepository';
import type { Payment, PaymentType, PayerType, PaymentStatus } from '../../domain/entities/Payment';
import type {
ICreatePaymentPresenter,
CreatePaymentResultDTO,
CreatePaymentViewModel,
PaymentDto,
} from '../presenters/ICreatePaymentPresenter';
import type { Payment, PaymentType, PayerType } from '../../domain/entities/Payment';
import { PaymentStatus } from '../../domain/entities/Payment';
import type { UseCase } from '@core/shared/application/UseCase';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
export interface CreatePaymentInput {
type: PaymentType;
@@ -23,17 +21,21 @@ export interface CreatePaymentInput {
seasonId?: string;
}
export interface CreatePaymentResult {
payment: Payment;
}
export type CreatePaymentErrorCode = never;
export class CreatePaymentUseCase
implements UseCase<CreatePaymentInput, CreatePaymentResultDTO, CreatePaymentViewModel, ICreatePaymentPresenter>
implements UseCase<CreatePaymentInput, void, CreatePaymentErrorCode>
{
constructor(private readonly paymentRepository: IPaymentRepository) {}
async execute(
input: CreatePaymentInput,
presenter: ICreatePaymentPresenter,
): Promise<void> {
presenter.reset();
constructor(
private readonly paymentRepository: IPaymentRepository,
private readonly output: UseCaseOutputPort<CreatePaymentResult>,
) {}
async execute(input: CreatePaymentInput): Promise<Result<void, ApplicationErrorCode<CreatePaymentErrorCode>>> {
const { type, amount, payerId, payerType, leagueId, seasonId } = input;
// Calculate platform fee (assume 5% for now)
@@ -50,32 +52,15 @@ export class CreatePaymentUseCase
payerId,
payerType,
leagueId,
seasonId,
status: PaymentStatus.PENDING,
createdAt: new Date(),
...(seasonId !== undefined ? { seasonId } : {}),
};
const createdPayment = await this.paymentRepository.create(payment);
const dto: PaymentDto = {
id: createdPayment.id,
type: createdPayment.type,
amount: createdPayment.amount,
platformFee: createdPayment.platformFee,
netAmount: createdPayment.netAmount,
payerId: createdPayment.payerId,
payerType: createdPayment.payerType,
leagueId: createdPayment.leagueId,
seasonId: createdPayment.seasonId,
status: createdPayment.status,
createdAt: createdPayment.createdAt,
completedAt: createdPayment.completedAt,
};
this.output.present({ payment: createdPayment });
const result: CreatePaymentResultDTO = {
payment: dto,
};
presenter.present(result);
return Result.ok(undefined);
}
}