mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
fix: Delete bank rule if it has no associations
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import { UnlinkBankRuleRecognizedTransactions } from '../UnlinkBankRuleRecognizedTransactions';
|
||||
import { IBankRuleEventDeletingPayload } from '../types';
|
||||
|
||||
@Service()
|
||||
export class UnlinkBankRuleOnDeleteBankRule {
|
||||
@Inject()
|
||||
private unlinkBankRule: UnlinkBankRuleRecognizedTransactions;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
*/
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.bankRules.onDeleting,
|
||||
this.unlinkBankRuleOutRecognizedTransactionsOnRuleDeleting.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlinks the bank rule out of recognized transactions.
|
||||
* @param {IBankRuleEventDeletingPayload} payload -
|
||||
*/
|
||||
private async unlinkBankRuleOutRecognizedTransactionsOnRuleDeleting({
|
||||
tenantId,
|
||||
ruleId,
|
||||
}: IBankRuleEventDeletingPayload) {
|
||||
await this.unlinkBankRule.unlinkBankRuleOutRecognizedTransactions(
|
||||
tenantId,
|
||||
ruleId
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user