feat: recognize uncategorized transactions

This commit is contained in:
Ahmed Bouhuolia
2024-06-18 21:43:54 +02:00
parent 906835c396
commit 0b5cee070a
17 changed files with 234 additions and 37 deletions

View File

@@ -0,0 +1,47 @@
import UncategorizedCashflowTransaction from '@/models/UncategorizedCashflowTransaction';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { transformToMapBy } from '@/utils';
import { Inject, Service } from 'typedi';
import { PromisePool } from '@supercharge/promise-pool';
@Service()
export class RecognizeedTranasctionsService {
@Inject()
private tenancy: HasTenancyService;
/**
* Regonized the uncategorized transactions.
* @param {number} tenantId
*/
public async recognizeTransactions(tenantId: number) {
const { UncategorizedCashflowTransaction, BankRule } =
this.tenancy.models(tenantId);
const uncategorizedTranasctions =
await UncategorizedCashflowTransaction.query().where(
'regonized_transaction_id',
null
);
const bankRules = await BankRule.query();
const bankRulesByAccountId = transformToMapBy(bankRules, 'accountId');
console.log(bankRulesByAccountId);
const regonizeTransaction = (
transaction: UncategorizedCashflowTransaction
) => {};
await PromisePool.withConcurrency(MIGRATION_CONCURRENCY)
.for(uncategorizedTranasctions)
.process((transaction: UncategorizedCashflowTransaction, index, pool) => {
return regonizeTransaction(transaction);
});
}
public async regonizeTransaction(
uncategorizedTransaction: UncategorizedCashflowTransaction
) {}
}
const MIGRATION_CONCURRENCY = 10;