From da024606ffc2af845e67b9c7cdf2a9eeea6ea8bd Mon Sep 17 00:00:00 2001 From: shancheas Date: Wed, 30 Apr 2025 07:46:19 +0700 Subject: [PATCH] feat: add logic to skip save transaction --- .../data/services/sales-price-formula-data.service.ts | 8 ++++++++ .../usecases/handlers/pos-transaction.handler.ts | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/modules/transaction/sales-price-formula/data/services/sales-price-formula-data.service.ts b/src/modules/transaction/sales-price-formula/data/services/sales-price-formula-data.service.ts index d3f667d..de23563 100644 --- a/src/modules/transaction/sales-price-formula/data/services/sales-price-formula-data.service.ts +++ b/src/modules/transaction/sales-price-formula/data/services/sales-price-formula-data.service.ts @@ -30,6 +30,14 @@ export class SalesPriceFormulaDataService extends BaseDataService percentage; + } + async itemTax(id: string) { const item = await this.item.findOne({ relations: ['tenant'], diff --git a/src/modules/transaction/transaction/domain/usecases/handlers/pos-transaction.handler.ts b/src/modules/transaction/transaction/domain/usecases/handlers/pos-transaction.handler.ts index fce39cc..012655d 100644 --- a/src/modules/transaction/transaction/domain/usecases/handlers/pos-transaction.handler.ts +++ b/src/modules/transaction/transaction/domain/usecases/handlers/pos-transaction.handler.ts @@ -104,7 +104,16 @@ export class PosTransactionHandler implements IEventHandler { apmTransactions.setLabel('Code', data?.code); apmTransactions.setLabel('Status', data?.status); - await this.dataService.create(queryRunner, TransactionModel, data); + // Check if this transaction should be sent to the "black hole" (not saved) + // This is only applicable for SETTLED transactions + const shouldSkipSaving = + data.status === STATUS.SETTLED && + (await this.formulaService.sentToBlackHole()); + + // If we shouldn't skip saving, then save the transaction + if (!shouldSkipSaving) { + await this.dataService.create(queryRunner, TransactionModel, data); + } /** * When transaction is cancel, set booking to Pending