mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat: uncategorize the cashflow transaction
This commit is contained in:
@@ -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.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user