feat: uncategorize the cashflow transaction

This commit is contained in:
Ahmed Bouhuolia
2024-03-10 02:53:57 +02:00
parent 2baf407814
commit b71c79fef5
16 changed files with 246 additions and 3 deletions

View File

@@ -2,12 +2,16 @@ import { Inject, Service } from 'typedi';
import events from '@/subscribers/events';
import { ICashflowTransactionUncategorizedPayload } from '@/interfaces';
import { DeleteCashflowTransaction } from '../DeleteCashflowTransactionService';
import HasTenancyService from '@/services/Tenancy/TenancyService';
@Service()
export class DeleteCashflowTransactionOnUncategorize {
@Inject()
private deleteCashflowTransactionService: DeleteCashflowTransaction;
@Inject()
private tenancy: HasTenancyService;
/**
* Attaches events with handlers.
*/
@@ -27,10 +31,18 @@ export class DeleteCashflowTransactionOnUncategorize {
oldUncategorizedTransaction,
trx,
}: ICashflowTransactionUncategorizedPayload) {
const { CashflowTransaction } = this.tenancy.models(tenantId);
// Deletes the cashflow transaction.
if (
oldUncategorizedTransaction.categorizeRefType === 'CashflowTransaction'
) {
await CashflowTransaction.query()
.findById(oldUncategorizedTransaction.categorizeRefId)
.patch({
uncategorizedTransactionId: null,
});
await this.deleteCashflowTransactionService.deleteCashflowTransaction(
tenantId,
oldUncategorizedTransaction.categorizeRefId