order calc
This commit is contained in:
@@ -67,6 +67,10 @@ export class PaymentService {
|
||||
throw new NotFoundException(OrderMessage.NOT_FOUND);
|
||||
}
|
||||
|
||||
if (!order.balance) {
|
||||
throw new NotFoundException('Balance is not set');
|
||||
}
|
||||
|
||||
let admin: null | Admin = null
|
||||
if (adminId) {
|
||||
admin = await this.adminRepository.findOne({ id: adminId })
|
||||
@@ -218,8 +222,8 @@ export class PaymentService {
|
||||
payment.transactionId = referenceId;
|
||||
// TODO : use decimal js
|
||||
// does need persist or not
|
||||
payment.order.paidAmount += payment.amount
|
||||
payment.order.balance -= payment.amount
|
||||
payment.order.paidAmount! += payment.amount
|
||||
payment.order.balance! -= payment.amount
|
||||
|
||||
await em.flush();
|
||||
return payment;
|
||||
@@ -257,8 +261,8 @@ export class PaymentService {
|
||||
payment.failedAt = null;
|
||||
|
||||
// TODO : use decimal js
|
||||
payment.order.paidAmount += payment.amount
|
||||
payment.order.balance -= payment.amount
|
||||
payment.order.paidAmount! += payment.amount
|
||||
payment.order.balance! -= payment.amount
|
||||
|
||||
em.persist(payment);
|
||||
em.persist(payment.order);
|
||||
@@ -282,8 +286,8 @@ export class PaymentService {
|
||||
}
|
||||
|
||||
if (payment.status == PaymentStatusEnum.Paid) {
|
||||
payment.order.paidAmount -= payment.amount
|
||||
payment.order.balance += payment.amount
|
||||
payment.order.paidAmount! -= payment.amount
|
||||
payment.order.balance! += payment.amount
|
||||
|
||||
em.persistAndFlush(payment.order)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user