module cleanup
This commit is contained in:
@@ -10,6 +10,7 @@ import type {
|
||||
IUpdatePaymentStatusPresenter,
|
||||
UpdatePaymentStatusResultDTO,
|
||||
UpdatePaymentStatusViewModel,
|
||||
PaymentDto,
|
||||
} from '../presenters/IUpdatePaymentStatusPresenter';
|
||||
import type { UseCase } from '@core/shared/application/UseCase';
|
||||
|
||||
@@ -31,35 +32,38 @@ export class UpdatePaymentStatusUseCase
|
||||
|
||||
const { paymentId, status } = input;
|
||||
|
||||
const payment = await this.paymentRepository.findById(paymentId);
|
||||
if (!payment) {
|
||||
throw new Error('Payment not found');
|
||||
const existingPayment = await this.paymentRepository.findById(paymentId);
|
||||
if (!existingPayment) {
|
||||
throw new Error(`Payment with id ${paymentId} not found`);
|
||||
}
|
||||
|
||||
payment.status = status;
|
||||
if (status === ('completed' as PaymentStatus)) {
|
||||
payment.completedAt = new Date();
|
||||
}
|
||||
|
||||
const updatedPayment = await this.paymentRepository.update(payment);
|
||||
|
||||
const dto: UpdatePaymentStatusResultDTO = {
|
||||
payment: {
|
||||
id: updatedPayment.id,
|
||||
type: updatedPayment.type,
|
||||
amount: updatedPayment.amount,
|
||||
platformFee: updatedPayment.platformFee,
|
||||
netAmount: updatedPayment.netAmount,
|
||||
payerId: updatedPayment.payerId,
|
||||
payerType: updatedPayment.payerType,
|
||||
leagueId: updatedPayment.leagueId,
|
||||
seasonId: updatedPayment.seasonId,
|
||||
status: updatedPayment.status,
|
||||
createdAt: updatedPayment.createdAt,
|
||||
completedAt: updatedPayment.completedAt,
|
||||
},
|
||||
const updatedPayment = {
|
||||
...existingPayment,
|
||||
status,
|
||||
completedAt: status === PaymentStatus.COMPLETED ? new Date() : existingPayment.completedAt,
|
||||
};
|
||||
|
||||
presenter.present(dto);
|
||||
const savedPayment = await this.paymentRepository.update(updatedPayment);
|
||||
|
||||
const dto: PaymentDto = {
|
||||
id: savedPayment.id,
|
||||
type: savedPayment.type,
|
||||
amount: savedPayment.amount,
|
||||
platformFee: savedPayment.platformFee,
|
||||
netAmount: savedPayment.netAmount,
|
||||
payerId: savedPayment.payerId,
|
||||
payerType: savedPayment.payerType,
|
||||
leagueId: savedPayment.leagueId,
|
||||
seasonId: savedPayment.seasonId,
|
||||
status: savedPayment.status,
|
||||
createdAt: savedPayment.createdAt,
|
||||
completedAt: savedPayment.completedAt,
|
||||
};
|
||||
|
||||
const result: UpdatePaymentStatusResultDTO = {
|
||||
payment: dto,
|
||||
};
|
||||
|
||||
presenter.present(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user