fix: Plaid transactions syncing

This commit is contained in:
Ahmed Bouhuolia
2024-07-12 23:43:20 +02:00
parent 81b26c6f13
commit 59168bc691
6 changed files with 74 additions and 12 deletions

View File

@@ -22,6 +22,10 @@ export class DecrementUncategorizedTransactionOnCategorize {
events.cashflow.onTransactionUncategorized,
this.incrementUnCategorizedTransactionsOnUncategorized.bind(this)
);
bus.subscribe(
events.cashflow.onTransactionUncategorizedCreated,
this.incrementUncategoirzedTransactionsOnCreated.bind(this)
);
}
/**
@@ -53,4 +57,22 @@ export class DecrementUncategorizedTransactionOnCategorize {
.findById(uncategorizedTransaction.accountId)
.increment('uncategorizedTransactions', 1);
}
/**
* Increments uncategorized transactions count once creating a new transaction.
* @param {ICommandCashflowCreatedPayload} payload -
*/
public async incrementUncategoirzedTransactionsOnCreated({
tenantId,
uncategorizedTransaction,
trx,
}: any) {
const { Account } = this.tenancy.models(tenantId);
if (!uncategorizedTransaction.accountId) return;
await Account.query(trx)
.findById(uncategorizedTransaction.accountId)
.increment('uncategorizedTransactions', 1);
}
}