mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat(server): categorize the synced bank transactions
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import { Service } from 'typedi';
|
||||
import { includes, camelCase, upperFirst } from 'lodash';
|
||||
import { IAccount } from '@/interfaces';
|
||||
import { IAccount, IUncategorizedCashflowTransaction } from '@/interfaces';
|
||||
import { getCashflowTransactionType } from './utils';
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import { CASHFLOW_TRANSACTION_TYPE, ERRORS } from './constants';
|
||||
import {
|
||||
CASHFLOW_DIRECTION,
|
||||
CASHFLOW_TRANSACTION_TYPE,
|
||||
ERRORS,
|
||||
} from './constants';
|
||||
import CashflowTransaction from '@/models/CashflowTransaction';
|
||||
|
||||
@Service()
|
||||
@@ -71,4 +75,28 @@ export class CommandCashflowValidator {
|
||||
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_CATEGORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {uncategorizeTransaction}
|
||||
* @param {string} transactionType
|
||||
* @throws {ServiceError(ERRORS.UNCATEGORIZED_TRANSACTION_TYPE_INVALID)}
|
||||
*/
|
||||
public validateUncategorizeTransactionType(
|
||||
uncategorizeTransaction: IUncategorizedCashflowTransaction,
|
||||
transactionType: string
|
||||
) {
|
||||
const type = getCashflowTransactionType(
|
||||
upperFirst(camelCase(transactionType)) as CASHFLOW_TRANSACTION_TYPE
|
||||
);
|
||||
if (
|
||||
(type.direction === CASHFLOW_DIRECTION.IN &&
|
||||
uncategorizeTransaction.isDepositTransaction) ||
|
||||
(type.direction === CASHFLOW_DIRECTION.OUT &&
|
||||
uncategorizeTransaction.isWithdrawalTransaction)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
throw new ServiceError(ERRORS.UNCATEGORIZED_TRANSACTION_TYPE_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user