feat: avoid categorize excluded transaction

This commit is contained in:
Ahmed Bouhuolia
2024-06-23 23:30:32 +02:00
parent 8dc2b18707
commit 66d2d6a612
2 changed files with 8 additions and 0 deletions

View File

@@ -12,6 +12,8 @@ import { Knex } from 'knex';
import { transformCategorizeTransToCashflow } from './utils';
import { CommandCashflowValidator } from './CommandCasflowValidator';
import NewCashflowTransactionService from './NewCashflowTransactionService';
import { ServiceError } from '@/exceptions';
import { ERRORS } from './constants';
@Service()
export class CategorizeCashflowTransaction {
@@ -47,6 +49,10 @@ export class CategorizeCashflowTransaction {
.findById(uncategorizedTransactionId)
.throwIfNotFound();
// Validate cannot categorize excluded transaction.
if (transaction.excluded) {
throw new ServiceError(ERRORS.CANNOT_CATEGORIZE_EXCLUDED_TRANSACTION);
}
// Validates the transaction shouldn't be categorized before.
this.commandValidators.validateTransactionShouldNotCategorized(transaction);

View File

@@ -15,6 +15,8 @@ export const ERRORS = {
'UNCATEGORIZED_TRANSACTION_TYPE_INVALID',
CANNOT_DELETE_TRANSACTION_CONVERTED_FROM_UNCATEGORIZED:
'CANNOT_DELETE_TRANSACTION_CONVERTED_FROM_UNCATEGORIZED',
CANNOT_CATEGORIZE_EXCLUDED_TRANSACTION: 'CANNOT_CATEGORIZE_EXCLUDED_TRANSACTION'
};
export enum CASHFLOW_DIRECTION {