mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 04:10:32 +00:00
feat: uncategorize the cashflow transaction
This commit is contained in:
@@ -86,6 +86,7 @@ export default class NewCashflowTransactionService {
|
||||
'creditAccountId',
|
||||
'branchId',
|
||||
'plaidTransactionId',
|
||||
'uncategorizedTransactionId',
|
||||
]);
|
||||
// Retreive the next invoice number.
|
||||
const autoNextNumber =
|
||||
|
||||
@@ -11,7 +11,8 @@ export const ERRORS = {
|
||||
ACCOUNT_HAS_ASSOCIATED_TRANSACTIONS: 'account_has_associated_transactions',
|
||||
TRANSACTION_ALREADY_CATEGORIZED: 'TRANSACTION_ALREADY_CATEGORIZED',
|
||||
TRANSACTION_ALREADY_UNCATEGORIZED: 'TRANSACTION_ALREADY_UNCATEGORIZED',
|
||||
UNCATEGORIZED_TRANSACTION_TYPE_INVALID: 'UNCATEGORIZED_TRANSACTION_TYPE_INVALID'
|
||||
UNCATEGORIZED_TRANSACTION_TYPE_INVALID: 'UNCATEGORIZED_TRANSACTION_TYPE_INVALID',
|
||||
CANNOT_DELETE_TRANSACTION_CONVERTED_FROM_UNCATEGORIZED: 'CANNOT_DELETE_TRANSACTION_CONVERTED_FROM_UNCATEGORIZED'
|
||||
};
|
||||
|
||||
export enum CASHFLOW_DIRECTION {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import { ICommandCashflowDeletingPayload } from '@/interfaces';
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import { ERRORS } from '../constants';
|
||||
|
||||
@Service()
|
||||
export class PreventDeleteTransactionOnDelete {
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
*/
|
||||
public attach = (bus) => {
|
||||
bus.subscribe(
|
||||
events.cashflow.onTransactionDeleting,
|
||||
this.preventDeleteCashflowTransactionHasUncategorizedTransaction.bind(
|
||||
this
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Prevent delete cashflow transaction has converted from uncategorized transaction.
|
||||
* @param {ICommandCashflowDeletingPayload} payload
|
||||
*/
|
||||
public async preventDeleteCashflowTransactionHasUncategorizedTransaction({
|
||||
tenantId,
|
||||
oldCashflowTransaction,
|
||||
trx,
|
||||
}: ICommandCashflowDeletingPayload) {
|
||||
if (oldCashflowTransaction.uncategorizedTransactionId) {
|
||||
throw new ServiceError(
|
||||
ERRORS.CANNOT_DELETE_TRANSACTION_CONVERTED_FROM_UNCATEGORIZED,
|
||||
'Cannot delete cashflow transaction converted from uncategorized transaction.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,7 @@ export const transformCategorizeTransToCashflow = (
|
||||
amount: uncategorizeModel.amount,
|
||||
transactionNumber: categorizeDTO.transactionNumber,
|
||||
transactionType: categorizeDTO.transactionType,
|
||||
uncategorizedTransactionId: uncategorizeModel.id,
|
||||
publish: true,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user