From 22f4e732db7d4e23bdbcf8600966d319ef06fff2 Mon Sep 17 00:00:00 2001 From: shancheas Date: Sat, 21 Sep 2024 23:04:59 +0700 Subject: [PATCH] fix: transaction NaN without discount --- .../usecases/managers/helpers/mapping-transaction.helper.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper.ts b/src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper.ts index 719a929..bbc00cf 100644 --- a/src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper.ts +++ b/src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper.ts @@ -165,7 +165,7 @@ export function mappingRevertTransaction(data, type) { const discountPercent = discount_value && +discount_value > 0 ? +discount_value / +payment_sub_total - : discount_percentage / 100; + : discount_percentage ?? 0 / 100; const discountValue = payment_sub_total * discountPercent; Object.assign(data, { @@ -192,7 +192,8 @@ export function mappingRevertTransaction(data, type) { item.bundling_items = item.item.bundling_items?.map((bundling) => { if (bundling.item_id) return bundling; - const basePrice = bundling.item_rates ?? bundling.base_price; + const basePrice = + (bundling.item_rates ?? bundling.base_price) * +item.qty; const discount = discountPercent * basePrice; const total = basePrice - discount;