From 02fb34e33a09752628d54d06bd00be908e7a65d9 Mon Sep 17 00:00:00 2001 From: Arjun Date: Mon, 9 Dec 2024 00:04:30 +0530 Subject: [PATCH] modify createTxnFromFile to make 2 API calls only if amount is not present --- src/app/core/services/transaction.service.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/core/services/transaction.service.ts b/src/app/core/services/transaction.service.ts index b3cd644ee7..cb68866631 100644 --- a/src/app/core/services/transaction.service.ts +++ b/src/app/core/services/transaction.service.ts @@ -196,17 +196,17 @@ export class TransactionService { return fileUploads$.pipe( switchMap((fileObjs) => { const fileIds = fileObjs.map((fileObj) => fileObj.id); - if (fileIds.length > 0) { + const isReceiptUpload = txn.hasOwnProperty('source') && Object.keys(txn).length === 1; + const isAmountPresent = !!txn.amount; + if ((isReceiptUpload || !isAmountPresent) && fileIds.length > 0) { return this.expensesService.createFromFile(fileIds[0], txn.source).pipe( switchMap((result) => { - // txn contains only source key when capturing receipt in bulk mode - if (txn.hasOwnProperty('source') && Object.keys(txn).length === 1) { - return of(this.transformExpense(result.data[0]).tx); - } else { - // capture receipt flow: patching the expense with any of the form values. - txn.file_ids = fileIds; + // capture receipt flow: patching the expense in case of amount not present + if (!isReceiptUpload && !isAmountPresent) { txn.id = result.data[0].id; return this.upsert(this.cleanupExpensePayload(txn)); + } else { + return of(this.transformExpense(result.data[0]).tx); } }) );