feat: Categorize the bank synced transactions

This commit is contained in:
Ahmed Bouhuolia
2024-02-29 23:53:26 +02:00
parent 0833baabda
commit ea8c5458ff
31 changed files with 901 additions and 35 deletions

View File

@@ -0,0 +1,40 @@
import { Inject, Service } from 'typedi';
import events from '@/subscribers/events';
import { ICashflowTransactionUncategorizedPayload } from '@/interfaces';
import { DeleteCashflowTransaction } from '../DeleteCashflowTransactionService';
@Service()
export class DeleteCashflowTransactionOnUncategorize {
@Inject()
private deleteCashflowTransactionService: DeleteCashflowTransaction;
/**
* Attaches events with handlers.
*/
public attach = (bus) => {
bus.subscribe(
events.cashflow.onTransactionUncategorized,
this.deleteCashflowTransactionOnUncategorize.bind(this)
);
};
/**
* Deletes the cashflow transaction on uncategorize transaction.
* @param {ICashflowTransactionUncategorizedPayload} payload
*/
public async deleteCashflowTransactionOnUncategorize({
tenantId,
oldUncategorizedTransaction,
trx,
}: ICashflowTransactionUncategorizedPayload) {
// Deletes the cashflow transaction.
if (
oldUncategorizedTransaction.categorizeRefType === 'CashflowTransaction'
) {
await this.deleteCashflowTransactionService.deleteCashflowTransaction(
tenantId,
oldUncategorizedTransaction.categorizeRefId
);
}
}
}