mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { Service, Inject } from 'typedi';
|
|
import I18nService from '@/services/I18n/I18nService';
|
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|
import { AccountTransformer } from './AccountTransform';
|
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
|
|
|
@Service()
|
|
export class GetAccount {
|
|
@Inject()
|
|
private tenancy: HasTenancyService;
|
|
|
|
@Inject()
|
|
private i18nService: I18nService;
|
|
|
|
@Inject()
|
|
private transformer: TransformerInjectable;
|
|
|
|
/**
|
|
* Retrieve the given account details.
|
|
* @param {number} tenantId
|
|
* @param {number} accountId
|
|
*/
|
|
public getAccount = async (tenantId: number, accountId: number) => {
|
|
const { Account } = this.tenancy.models(tenantId);
|
|
|
|
// Find the given account or throw not found error.
|
|
const account = await Account.query().findById(accountId).throwIfNotFound();
|
|
|
|
// Transformes the account model to POJO.
|
|
const transformed = await this.transformer.transform(
|
|
tenantId,
|
|
account,
|
|
new AccountTransformer()
|
|
);
|
|
return this.i18nService.i18nApply(
|
|
[['accountTypeLabel'], ['accountNormalFormatted']],
|
|
transformed,
|
|
tenantId
|
|
);
|
|
};
|
|
}
|