mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat: Categorize the bank synced transactions
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user