Skip to content

Commit

Permalink
modify createTxnFromFile to make 2 API calls only if amount is not pr…
Browse files Browse the repository at this point in the history
…esent
  • Loading branch information
arjunaj5 committed Dec 8, 2024
1 parent 469dea5 commit 02fb34e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/app/core/services/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
})
);
Expand Down

0 comments on commit 02fb34e

Please sign in to comment.