Merge pull request #587 from bigcapitalhq/big-244-uncategorize-bank-transactions-in-bulk

feat: Uncategorize bank transactions in bulk
This commit is contained in:
Ahmed Bouhuolia
2024-08-12 10:11:55 +02:00
committed by GitHub
11 changed files with 323 additions and 6 deletions

View File

@@ -21,6 +21,7 @@ import GetCashflowAccountsService from './GetCashflowAccountsService';
import { GetCashflowTransactionService } from './GetCashflowTransactionsService';
import { GetRecognizedTransactionsService } from './GetRecongizedTransactions';
import { GetRecognizedTransactionService } from './GetRecognizedTransaction';
import { UncategorizeCashflowTransactionsBulk } from './UncategorizeCashflowTransactionsBulk';
@Service()
export class CashflowApplication {
@@ -39,6 +40,9 @@ export class CashflowApplication {
@Inject()
private uncategorizeTransactionService: UncategorizeCashflowTransaction;
@Inject()
private uncategorizeTransasctionsService: UncategorizeCashflowTransactionsBulk;
@Inject()
private categorizeTransactionService: CategorizeCashflowTransaction;
@@ -155,6 +159,22 @@ export class CashflowApplication {
);
}
/**
* Uncategorize the given transactions in bulk.
* @param {number} tenantId
* @param {number | Array<number>} transactionId
* @returns
*/
public uncategorizeTransactions(
tenantId: number,
transactionId: number | Array<number>
) {
return this.uncategorizeTransasctionsService.uncategorizeBulk(
tenantId,
transactionId
);
}
/**
* Categorize the given cashflow transaction.
* @param {number} tenantId
@@ -241,9 +261,9 @@ export class CashflowApplication {
/**
* Retrieves the recognized transaction of the given uncategorized transaction.
* @param {number} tenantId
* @param {number} uncategorizedTransactionId
* @returns
* @param {number} tenantId
* @param {number} uncategorizedTransactionId
* @returns
*/
public getRecognizedTransaction(
tenantId: number,

View File

@@ -0,0 +1,37 @@
import PromisePool from '@supercharge/promise-pool';
import { castArray } from 'lodash';
import { Service, Inject } from 'typedi';
import HasTenancyService from '../Tenancy/TenancyService';
import { UncategorizeCashflowTransaction } from './UncategorizeCashflowTransaction';
@Service()
export class UncategorizeCashflowTransactionsBulk {
@Inject()
private tenancy: HasTenancyService;
@Inject()
private uncategorizeTransaction: UncategorizeCashflowTransaction;
/**
* Uncategorize the given bank transactions in bulk.
* @param {number} tenantId
* @param {number} uncategorizedTransactionId
*/
public async uncategorizeBulk(
tenantId: number,
uncategorizedTransactionId: number | Array<number>
) {
const uncategorizedTransactionIds = castArray(uncategorizedTransactionId);
const result = await PromisePool.withConcurrency(MIGRATION_CONCURRENCY)
.for(uncategorizedTransactionIds)
.process(async (_uncategorizedTransactionId: number, index, pool) => {
await this.uncategorizeTransaction.uncategorize(
tenantId,
_uncategorizedTransactionId
);
});
}
}
const MIGRATION_CONCURRENCY = 1;