mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat(server): move updating plaid transactions to background job
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import Container, { Service } from 'typedi';
|
||||
import { PlaidUpdateTransactions } from './PlaidUpdateTransactions';
|
||||
import { IPlaidItemCreatedEventPayload } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class PlaidFetchTransactionsJob {
|
||||
/**
|
||||
* Constructor method.
|
||||
*/
|
||||
constructor(agenda) {
|
||||
agenda.define(
|
||||
'plaid-update-account-transactions',
|
||||
{ priority: 'high', concurrency: 2 },
|
||||
this.handler
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the function.
|
||||
*/
|
||||
private handler = async (job, done: Function) => {
|
||||
const { tenantId, plaidItemId } = job.attrs
|
||||
.data as IPlaidItemCreatedEventPayload;
|
||||
|
||||
const plaidFetchTransactionsService = Container.get(
|
||||
PlaidUpdateTransactions
|
||||
);
|
||||
try {
|
||||
await plaidFetchTransactionsService.updateTransactions(
|
||||
tenantId,
|
||||
plaidItemId
|
||||
);
|
||||
done();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
done(error);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user