refactor(nestjs): bank transactions matching

This commit is contained in:
Ahmed Bouhuolia
2025-06-05 14:41:26 +02:00
parent f87bd341e9
commit 51988dba3b
43 changed files with 484 additions and 105 deletions

View File

@@ -21,7 +21,7 @@ import { ServiceError } from '@/modules/Items/ServiceError';
import { UncategorizedBankTransaction } from '@/modules/BankingTransactions/models/UncategorizedBankTransaction';
import { events } from '@/common/events/events';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { MatchBankTransactionDto } from '../dtos/MatchBankTransaction.dto';
import { MatchTransactionEntryDto } from '../dtos/MatchBankTransaction.dto';
@Injectable()
export class MatchBankTransactions {
@@ -107,16 +107,15 @@ export class MatchBankTransactions {
/**
* Matches the given uncategorized transaction to the given references.
* @param {number} tenantId
* @param {number} uncategorizedTransactionId
* @returns {Promise<void>}
*/
public async matchTransaction(
uncategorizedTransactionId: number | Array<number>,
matchedTransactionsDto: MatchBankTransactionDto,
matchedTransactionsDto: MatchTransactionEntryDto | Array<MatchTransactionEntryDto>,
): Promise<void> {
const uncategorizedTransactionIds = castArray(uncategorizedTransactionId);
const matchedTransactions = matchedTransactionsDto.entries;
const matchedTransactions = castArray(matchedTransactionsDto);
// Validates the given matching transactions DTO.
await this.validate(uncategorizedTransactionIds, matchedTransactions);
@@ -131,7 +130,7 @@ export class MatchBankTransactions {
// Matches the given transactions under promise pool concurrency controlling.
await PromisePool.withConcurrency(10)
.for(matchedTransactions)
.process(async (matchedTransaction) => {
.process(async (matchedTransaction: MatchTransactionEntryDto) => {
const getMatchedTransactionsService =
this.matchedBankTransactions.registry.get(
matchedTransaction.referenceType,