mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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()
|
||||
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)
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user