diff --git a/src/modules/configuration/couch/domain/managers/booking.handler.ts b/src/modules/configuration/couch/domain/managers/booking.handler.ts index 0ce1ec7..8c6d4e4 100644 --- a/src/modules/configuration/couch/domain/managers/booking.handler.ts +++ b/src/modules/configuration/couch/domain/managers/booking.handler.ts @@ -97,9 +97,9 @@ export class ChangeStatusBookingHandler }, relations: ['items'], }); - mappingTransaction(booking); - console.log('change status', { dataID, couchData, booking }); + mappingTransaction(booking); + console.log('after mapping'); if (!couchData) { console.log('save data to couch'); diff --git a/src/modules/configuration/mail/domain/handlers/payment-transaction.handler.ts b/src/modules/configuration/mail/domain/handlers/payment-transaction.handler.ts index 7779add..355c75b 100644 --- a/src/modules/configuration/mail/domain/handlers/payment-transaction.handler.ts +++ b/src/modules/configuration/mail/domain/handlers/payment-transaction.handler.ts @@ -32,6 +32,7 @@ export class PaymentTransactionHandler const current_data = event.data.data; const data_id = current_data.transaction_id ?? event.data.id; const from_refund = event.data.module == TABLE_NAME.REFUND; + console.log('payment handlet', { data_id }); const payments = await this.paymentService.getManyByOptions({ where: { 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 487ef24..f319770 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 @@ -5,86 +5,90 @@ import { } from 'src/modules/transaction/transaction/constants'; export function mappingTransaction(data, refundId?: string) { - let payment_type_bank: any = null; - const season_period = { - id: data.season_period_id, - holiday_name: data.season_period_name, - season_type: { - id: data.season_period_type_id, - name: data.season_period_type_name, - }, - }; - - if (data.payment_type_method_id || data.payment_type_method_name) { - payment_type_bank = { - id: data.payment_type_method_id, - issuer_name: data.payment_type_method_name, - account_number: data.payment_type_method_number, - qr_image: data.payment_type_method_qr, + try { + let payment_type_bank: any = null; + const season_period = { + id: data.season_period_id, + holiday_name: data.season_period_name, + season_type: { + id: data.season_period_type_id, + name: data.season_period_type_name, + }, }; - } - const items = data?.['items']?.map((itemData) => { - let tenant; - let refund = itemData.refunds?.find( - (item) => ![STATUS.CANCEL].includes(item.refund.status), - ); - - if (itemData.item_tenant_id) { - tenant = { - id: itemData.item_tenant_id, - name: itemData.item_tenant_name, - share_margin: itemData.item_tenant_share_margin, + if (data.payment_type_method_id || data.payment_type_method_name) { + payment_type_bank = { + id: data.payment_type_method_id, + issuer_name: data.payment_type_method_name, + account_number: data.payment_type_method_number, + qr_image: data.payment_type_method_qr, }; } - if (refundId) - refund = itemData.refunds?.find((item) => item.refund.id == refundId); + const items = data?.['items']?.map((itemData) => { + let tenant; + let refund = itemData.refunds?.find( + (item) => ![STATUS.CANCEL].includes(item.refund.status), + ); - return { - item: { - id: itemData.item_id, - name: itemData.item_name, - item_type: itemData.item_type, - base_price: itemData.item_price, - hpp: itemData.item_hpp, - tenant: tenant, - item_category: { - id: itemData.item_category_id, - name: itemData.item_category_name, + if (itemData.item_tenant_id) { + tenant = { + id: itemData.item_tenant_id, + name: itemData.item_tenant_name, + share_margin: itemData.item_tenant_share_margin, + }; + } + + if (refundId) + refund = itemData.refunds?.find((item) => item.refund.id == refundId); + + return { + item: { + id: itemData.item_id, + name: itemData.item_name, + item_type: itemData.item_type, + base_price: itemData.item_price, + hpp: itemData.item_hpp, + tenant: tenant, + item_category: { + id: itemData.item_category_id, + name: itemData.item_category_name, + }, }, - }, - id: itemData.id, + id: itemData.id, + refund: refund, + qty: itemData.qty, + qty_remaining: itemData.qty_remaining, + total_price_refund: refund?.refund_total ?? 0, + total_price: itemData.total_price, + }; + }); + + const refund = data.refunds?.find( + (refund) => ![STATUS.CANCEL].includes(refund.status), + ); + + Object.assign(data, { + season_period: season_period, + items: items, + payment_type_bank: payment_type_bank, refund: refund, - qty: itemData.qty, - qty_remaining: itemData.qty_remaining, - total_price_refund: refund?.refund_total ?? 0, - total_price: itemData.total_price, - }; - }); + }); - const refund = data.refunds?.find( - (refund) => ![STATUS.CANCEL].includes(refund.status), - ); + delete data.refunds; - Object.assign(data, { - season_period: season_period, - items: items, - payment_type_bank: payment_type_bank, - refund: refund, - }); + delete data.season_period_id; + delete data.season_period_name; + delete data.season_period_type_id; + delete data.season_period_type_name; - delete data.refunds; - - delete data.season_period_id; - delete data.season_period_name; - delete data.season_period_type_id; - delete data.season_period_type_name; - - delete data.payment_type_method_id; - delete data.payment_type_method_name; - delete data.payment_type_method_number; - delete data.payment_type_method_qr; + delete data.payment_type_method_id; + delete data.payment_type_method_name; + delete data.payment_type_method_number; + delete data.payment_type_method_qr; + } catch (error) { + console.log('error mapping transactin', error); + } } export function mappingRevertTransaction(data, type) {