mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
31 lines
904 B
TypeScript
31 lines
904 B
TypeScript
import { Service, Inject } from 'typedi';
|
|
import { ServiceError } from '@/exceptions';
|
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|
import { ERRORS } from './constants';
|
|
|
|
@Service()
|
|
export default class CashflowDeleteAccount {
|
|
@Inject()
|
|
private tenancy: HasTenancyService;
|
|
|
|
/**
|
|
* Validate the account has no associated cashflow transactions.
|
|
* @param {number} tenantId
|
|
* @param {number} accountId
|
|
*/
|
|
public validateAccountHasNoCashflowEntries = async (
|
|
tenantId: number,
|
|
accountId: number
|
|
) => {
|
|
const { CashflowTransactionLine } = this.tenancy.models(tenantId);
|
|
|
|
const associatedLines = await CashflowTransactionLine.query()
|
|
.where('creditAccountId', accountId)
|
|
.orWhere('cashflowAccountId', accountId);
|
|
|
|
if (associatedLines.length > 0) {
|
|
throw new ServiceError(ERRORS.ACCOUNT_HAS_ASSOCIATED_TRANSACTIONS)
|
|
}
|
|
};
|
|
}
|