59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
/**
|
|
* Application Use Case: GetPaymentsUseCase
|
|
*
|
|
* Retrieves payments based on filters.
|
|
*/
|
|
|
|
import type { IPaymentRepository } from '../../domain/repositories/IPaymentRepository';
|
|
import type { PaymentType } from '../../domain/entities/Payment';
|
|
import type {
|
|
IGetPaymentsPresenter,
|
|
GetPaymentsResultDTO,
|
|
GetPaymentsViewModel,
|
|
PaymentDto,
|
|
} from '../presenters/IGetPaymentsPresenter';
|
|
import type { UseCase } from '@core/shared/application/UseCase';
|
|
|
|
export interface GetPaymentsInput {
|
|
leagueId?: string;
|
|
payerId?: string;
|
|
type?: PaymentType;
|
|
}
|
|
|
|
export class GetPaymentsUseCase
|
|
implements UseCase<GetPaymentsInput, GetPaymentsResultDTO, GetPaymentsViewModel, IGetPaymentsPresenter>
|
|
{
|
|
constructor(private readonly paymentRepository: IPaymentRepository) {}
|
|
|
|
async execute(
|
|
input: GetPaymentsInput,
|
|
presenter: IGetPaymentsPresenter,
|
|
): Promise<void> {
|
|
presenter.reset();
|
|
|
|
const { leagueId, payerId, type } = input;
|
|
|
|
const payments = await this.paymentRepository.findByFilters({ leagueId, payerId, type });
|
|
|
|
const dtos: PaymentDto[] = payments.map(payment => ({
|
|
id: payment.id,
|
|
type: payment.type,
|
|
amount: payment.amount,
|
|
platformFee: payment.platformFee,
|
|
netAmount: payment.netAmount,
|
|
payerId: payment.payerId,
|
|
payerType: payment.payerType,
|
|
leagueId: payment.leagueId,
|
|
seasonId: payment.seasonId,
|
|
status: payment.status,
|
|
createdAt: payment.createdAt,
|
|
completedAt: payment.completedAt,
|
|
}));
|
|
|
|
const dto: GetPaymentsResultDTO = {
|
|
payments: dtos,
|
|
};
|
|
|
|
presenter.present(dto);
|
|
}
|
|
} |