feat: run re-recognizing bank transactions on edit bank rule

This commit is contained in:
Ahmed Bouhuolia
2024-08-12 20:07:01 +02:00
parent 193a86cf30
commit cf4bb3007e
6 changed files with 24 additions and 8 deletions

View File

@@ -116,6 +116,6 @@ const determineFieldType = (field: string): string => {
case 'description':
case 'payee':
default:
return 'unknown';
return 'text';
}
};

View File

@@ -1,4 +1,5 @@
import { Inject, Service } from 'typedi';
import { isEqual, omit } from 'lodash';
import events from '@/subscribers/events';
import {
IBankRuleEventCreatedPayload,
@@ -55,10 +56,22 @@ export class TriggerRecognizedTransactions {
private async recognizedTransactionsOnRuleEdited({
tenantId,
editRuleDTO,
oldBankRule,
bankRule,
ruleId,
}: IBankRuleEventEditedPayload) {
const payload = { tenantId, ruleId };
// Cannot continue if the new and old bank rule values are the same,
// after excluding `createdAt` and `updatedAt` dates.
if (
isEqual(
omit(bankRule, ['createdAt', 'updatedAt']),
omit(oldBankRule, ['createdAt', 'updatedAt'])
)
) {
return;
}
await this.agenda.now(
'rerecognize-uncategorized-transactions-job',
payload