feat: wip uncategorize bank transaction

This commit is contained in:
Ahmed Bouhuolia
2024-08-03 23:30:23 +02:00
parent d74337fb94
commit fdf3e34f1c
8 changed files with 91 additions and 31 deletions

View File

@@ -50,12 +50,15 @@ export class DecrementUncategorizedTransactionOnCategorize {
*/
public async incrementUnCategorizedTransactionsOnUncategorized({
tenantId,
uncategorizedTransaction,
uncategorizedTransactions,
}: ICashflowTransactionUncategorizedPayload) {
const { Account } = this.tenancy.models(tenantId);
const uncategorizedTransactionIds = uncategorizedTransactions?.map(
(t) => t.id
);
await Account.query()
.findById(uncategorizedTransaction.accountId)
.whereIn('id', uncategorizedTransactionIds)
.increment('uncategorizedTransactions', 1);
}

View File

@@ -1,8 +1,10 @@
import { Inject, Service } from 'typedi';
import { PromisePool } from '@supercharge/promise-pool';
import events from '@/subscribers/events';
import { ICashflowTransactionUncategorizedPayload } from '@/interfaces';
import { DeleteCashflowTransaction } from '../DeleteCashflowTransactionService';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { ServiceError } from '@/exceptions';
@Service()
export class DeleteCashflowTransactionOnUncategorize {
@@ -25,18 +27,27 @@ export class DeleteCashflowTransactionOnUncategorize {
*/
public async deleteCashflowTransactionOnUncategorize({
tenantId,
oldUncategorizedTransaction,
oldUncategorizedTransactions,
trx,
}: ICashflowTransactionUncategorizedPayload) {
// Deletes the cashflow transaction.
if (
oldUncategorizedTransaction.categorizeRefType === 'CashflowTransaction'
) {
await this.deleteCashflowTransactionService.deleteCashflowTransaction(
tenantId,
const _oldUncategorizedTransactions = oldUncategorizedTransactions.filter(
(transaction) => transaction.categorizeRefType === 'CashflowTransaction'
);
oldUncategorizedTransaction.categorizeRefId
);
// Deletes the cashflow transaction.
if (_oldUncategorizedTransactions.length > 0) {
const result = await PromisePool.withConcurrency(1)
.for(_oldUncategorizedTransactions)
.process(async (oldUncategorizedTransaction) => {
await this.deleteCashflowTransactionService.deleteCashflowTransaction(
tenantId,
oldUncategorizedTransaction.categorizeRefId,
trx
);
});
if (result.errors) {
throw new ServiceError('SOMETHING_WRONG');
}
}
}
}