|
|
|
@ -1,9 +1,6 @@
|
|
|
|
|
import { PortfolioService } from '@ghostfolio/api/app/portfolio/portfolio.service';
|
|
|
|
|
import { UserService } from '@ghostfolio/api/app/user/user.service';
|
|
|
|
|
import {
|
|
|
|
|
nullifyValuesInObject,
|
|
|
|
|
nullifyValuesInObjects
|
|
|
|
|
} from '@ghostfolio/api/helper/object.helper';
|
|
|
|
|
import { RedactValuesInResponseInterceptor } from '@ghostfolio/api/interceptors/redact-values-in-response.interceptor';
|
|
|
|
|
import { ImpersonationService } from '@ghostfolio/api/services/impersonation.service';
|
|
|
|
|
import { Accounts } from '@ghostfolio/common/interfaces';
|
|
|
|
|
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
|
|
|
|
@ -22,7 +19,8 @@ import {
|
|
|
|
|
Param,
|
|
|
|
|
Post,
|
|
|
|
|
Put,
|
|
|
|
|
UseGuards
|
|
|
|
|
UseGuards,
|
|
|
|
|
UseInterceptors
|
|
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import { REQUEST } from '@nestjs/core';
|
|
|
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
@ -85,6 +83,7 @@ export class AccountController {
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
|
|
|
@UseInterceptors(RedactValuesInResponseInterceptor)
|
|
|
|
|
public async getAllAccounts(
|
|
|
|
|
@Headers('impersonation-id') impersonationId
|
|
|
|
|
): Promise<Accounts> {
|
|
|
|
@ -94,39 +93,15 @@ export class AccountController {
|
|
|
|
|
this.request.user.id
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let accountsWithAggregations =
|
|
|
|
|
await this.portfolioService.getAccountsWithAggregations({
|
|
|
|
|
userId: impersonationUserId || this.request.user.id,
|
|
|
|
|
withExcludedAccounts: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
impersonationUserId ||
|
|
|
|
|
this.userService.isRestrictedView(this.request.user)
|
|
|
|
|
) {
|
|
|
|
|
accountsWithAggregations = {
|
|
|
|
|
...nullifyValuesInObject(accountsWithAggregations, [
|
|
|
|
|
'totalBalanceInBaseCurrency',
|
|
|
|
|
'totalValueInBaseCurrency'
|
|
|
|
|
]),
|
|
|
|
|
accounts: nullifyValuesInObjects(accountsWithAggregations.accounts, [
|
|
|
|
|
'balance',
|
|
|
|
|
'balanceInBaseCurrency',
|
|
|
|
|
'convertedBalance',
|
|
|
|
|
'fee',
|
|
|
|
|
'quantity',
|
|
|
|
|
'unitPrice',
|
|
|
|
|
'value',
|
|
|
|
|
'valueInBaseCurrency'
|
|
|
|
|
])
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return accountsWithAggregations;
|
|
|
|
|
return this.portfolioService.getAccountsWithAggregations({
|
|
|
|
|
userId: impersonationUserId || this.request.user.id,
|
|
|
|
|
withExcludedAccounts: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id')
|
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
|
|
|
@UseInterceptors(RedactValuesInResponseInterceptor)
|
|
|
|
|
public async getAccountById(
|
|
|
|
|
@Headers('impersonation-id') impersonationId,
|
|
|
|
|
@Param('id') id: string
|
|
|
|
@ -137,35 +112,13 @@ export class AccountController {
|
|
|
|
|
this.request.user.id
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let accountsWithAggregations =
|
|
|
|
|
const accountsWithAggregations =
|
|
|
|
|
await this.portfolioService.getAccountsWithAggregations({
|
|
|
|
|
filters: [{ id, type: 'ACCOUNT' }],
|
|
|
|
|
userId: impersonationUserId || this.request.user.id,
|
|
|
|
|
withExcludedAccounts: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
impersonationUserId ||
|
|
|
|
|
this.userService.isRestrictedView(this.request.user)
|
|
|
|
|
) {
|
|
|
|
|
accountsWithAggregations = {
|
|
|
|
|
...nullifyValuesInObject(accountsWithAggregations, [
|
|
|
|
|
'totalBalanceInBaseCurrency',
|
|
|
|
|
'totalValueInBaseCurrency'
|
|
|
|
|
]),
|
|
|
|
|
accounts: nullifyValuesInObjects(accountsWithAggregations.accounts, [
|
|
|
|
|
'balance',
|
|
|
|
|
'balanceInBaseCurrency',
|
|
|
|
|
'convertedBalance',
|
|
|
|
|
'fee',
|
|
|
|
|
'quantity',
|
|
|
|
|
'unitPrice',
|
|
|
|
|
'value',
|
|
|
|
|
'valueInBaseCurrency'
|
|
|
|
|
])
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return accountsWithAggregations.accounts[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|