- feat: Optimize tenancy software architecture.

This commit is contained in:
Ahmed Bouhuolia
2020-08-30 22:11:14 +02:00
parent 74321a2886
commit ca251a2d28
53 changed files with 1581 additions and 1055 deletions

View File

@@ -0,0 +1,29 @@
import { Inject, Service } from 'typedi';
import TenancyService from '@/services/Tenancy/TenancyService';
@Service()
export default class AccountsService {
@Inject()
tenancy: TenancyService;
async isAccountExists(tenantId: number, accountId: number) {
const { Account } = this.tenancy.models(tenantId);
const foundAccounts = await Account.query()
.where('id', accountId);
return foundAccounts.length > 0;
}
async getAccountByType(tenantId: number, accountTypeKey: string) {
const { AccountType, Account } = this.tenancy.models(tenantId);
const accountType = await AccountType.query()
.where('key', accountTypeKey)
.first();
const account = await Account.query()
.where('account_type_id', accountType.id)
.first();
return account;
}
}