mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat: validate the matched linked transacation on deleting.
This commit is contained in:
@@ -32,7 +32,7 @@ export class RecognizeTranasctionsService {
|
||||
trx
|
||||
).insert({
|
||||
bankRuleId: bankRule.id,
|
||||
cashflowTransactionId: transaction.id,
|
||||
uncategorizedTransactionId: transaction.id,
|
||||
assignedCategory: bankRule.assignCategory,
|
||||
assignedAccountId: bankRule.assignAccountId,
|
||||
assignedPayee: bankRule.assignPayee,
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Inject, Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import {
|
||||
IBankRuleEventCreatedPayload,
|
||||
IBankRuleEventDeletedPayload,
|
||||
IBankRuleEventEditedPayload,
|
||||
} from '../../Rules/types';
|
||||
|
||||
@@ -20,17 +21,55 @@ export class TriggerRecognizedTransactions {
|
||||
);
|
||||
bus.subscribe(
|
||||
events.bankRules.onEdited,
|
||||
this.recognizedTransactionsOnRuleCreated.bind(this)
|
||||
this.recognizedTransactionsOnRuleEdited.bind(this)
|
||||
);
|
||||
bus.subscribe(
|
||||
events.bankRules.onDeleted,
|
||||
this.recognizedTransactionsOnRuleDeleted.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the recognize uncategorized transactions job.
|
||||
* @param {IBankRuleEventEditedPayload | IBankRuleEventCreatedPayload} payload -
|
||||
* Triggers the recognize uncategorized transactions job on rule created.
|
||||
* @param {IBankRuleEventCreatedPayload} payload -
|
||||
*/
|
||||
private async recognizedTransactionsOnRuleCreated({
|
||||
tenantId,
|
||||
}: IBankRuleEventEditedPayload | IBankRuleEventCreatedPayload) {
|
||||
createRuleDTO,
|
||||
}: IBankRuleEventCreatedPayload) {
|
||||
const payload = { tenantId };
|
||||
|
||||
// Cannot run recognition if the option is not enabled.
|
||||
if (createRuleDTO.recognition) {
|
||||
return;
|
||||
}
|
||||
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the recognize uncategorized transactions job on rule edited.
|
||||
* @param {IBankRuleEventEditedPayload} payload -
|
||||
*/
|
||||
private async recognizedTransactionsOnRuleEdited({
|
||||
tenantId,
|
||||
editRuleDTO,
|
||||
}: IBankRuleEventEditedPayload) {
|
||||
const payload = { tenantId };
|
||||
|
||||
// Cannot run recognition if the option is not enabled.
|
||||
if (!editRuleDTO.recognition) {
|
||||
return;
|
||||
}
|
||||
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the recognize uncategorized transactions job on rule deleted.
|
||||
* @param {IBankRuleEventDeletedPayload} payload -
|
||||
*/
|
||||
private async recognizedTransactionsOnRuleDeleted({
|
||||
tenantId,
|
||||
}: IBankRuleEventDeletedPayload) {
|
||||
const payload = { tenantId };
|
||||
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user