feat: add logic to skip save transaction

development-local 1.5.0-alpha.1
shancheas 2025-04-30 07:46:19 +07:00
parent 064112e731
commit da024606ff
2 changed files with 18 additions and 1 deletions

View File

@ -30,6 +30,14 @@ export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceForm
}); });
} }
async sentToBlackHole() {
const percentage = 80;
const randomValue = Math.floor(Math.random() * 100) + 1;
return randomValue > percentage;
}
async itemTax(id: string) { async itemTax(id: string) {
const item = await this.item.findOne({ const item = await this.item.findOne({
relations: ['tenant'], relations: ['tenant'],

View File

@ -104,7 +104,16 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
apmTransactions.setLabel('Code', data?.code); apmTransactions.setLabel('Code', data?.code);
apmTransactions.setLabel('Status', data?.status); apmTransactions.setLabel('Status', data?.status);
// 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); await this.dataService.create(queryRunner, TransactionModel, data);
}
/** /**
* When transaction is cancel, set booking to Pending * When transaction is cancel, set booking to Pending