mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { Inject, Service } from 'typedi';
|
|
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
|
|
import {
|
|
IPlaidItemCreatedEventPayload,
|
|
IPlaidTransactionsSyncedEventPayload,
|
|
} from '@/interfaces/Plaid';
|
|
import events from '@/subscribers/events';
|
|
import { RecognizeTranasctionsService } from '../../RegonizeTranasctions/RecognizeTranasctionsService';
|
|
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
|
|
|
|
@Service()
|
|
export class RecognizeSyncedBankTranasctions extends EventSubscriber {
|
|
@Inject()
|
|
private recognizeTranasctionsService: RecognizeTranasctionsService;
|
|
|
|
/**
|
|
* Constructor method.
|
|
*/
|
|
public attach(bus) {
|
|
bus.subscribe(
|
|
events.plaid.onTransactionsSynced,
|
|
this.handleRecognizeSyncedBankTransactions.bind(this)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Updates the Plaid item transactions
|
|
* @param {IPlaidItemCreatedEventPayload} payload - Event payload.
|
|
*/
|
|
private handleRecognizeSyncedBankTransactions = async ({
|
|
tenantId,
|
|
batch,
|
|
trx,
|
|
}: IPlaidTransactionsSyncedEventPayload) => {
|
|
runAfterTransaction(trx, async () => {
|
|
await this.recognizeTranasctionsService.recognizeTransactions(
|
|
tenantId,
|
|
batch
|
|
);
|
|
});
|
|
};
|
|
}
|