|
|
@ -3,6 +3,8 @@ import { PortfolioService } from '@ghostfolio/api/app/portfolio/portfolio.servic
|
|
|
|
import { HasPermission } from '@ghostfolio/api/decorators/has-permission.decorator';
|
|
|
|
import { HasPermission } from '@ghostfolio/api/decorators/has-permission.decorator';
|
|
|
|
import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard';
|
|
|
|
import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard';
|
|
|
|
import { RedactValuesInResponseInterceptor } from '@ghostfolio/api/interceptors/redact-values-in-response/redact-values-in-response.interceptor';
|
|
|
|
import { RedactValuesInResponseInterceptor } from '@ghostfolio/api/interceptors/redact-values-in-response/redact-values-in-response.interceptor';
|
|
|
|
|
|
|
|
import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.interceptor';
|
|
|
|
|
|
|
|
import { ApiService } from '@ghostfolio/api/services/api/api.service';
|
|
|
|
import { ImpersonationService } from '@ghostfolio/api/services/impersonation/impersonation.service';
|
|
|
|
import { ImpersonationService } from '@ghostfolio/api/services/impersonation/impersonation.service';
|
|
|
|
import { HEADER_KEY_IMPERSONATION } from '@ghostfolio/common/config';
|
|
|
|
import { HEADER_KEY_IMPERSONATION } from '@ghostfolio/common/config';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
@ -26,6 +28,7 @@ import {
|
|
|
|
Param,
|
|
|
|
Param,
|
|
|
|
Post,
|
|
|
|
Post,
|
|
|
|
Put,
|
|
|
|
Put,
|
|
|
|
|
|
|
|
Query,
|
|
|
|
UseGuards,
|
|
|
|
UseGuards,
|
|
|
|
UseInterceptors
|
|
|
|
UseInterceptors
|
|
|
|
} from '@nestjs/common';
|
|
|
|
} from '@nestjs/common';
|
|
|
@ -44,6 +47,7 @@ export class AccountController {
|
|
|
|
public constructor(
|
|
|
|
public constructor(
|
|
|
|
private readonly accountBalanceService: AccountBalanceService,
|
|
|
|
private readonly accountBalanceService: AccountBalanceService,
|
|
|
|
private readonly accountService: AccountService,
|
|
|
|
private readonly accountService: AccountService,
|
|
|
|
|
|
|
|
private readonly apiService: ApiService,
|
|
|
|
private readonly impersonationService: ImpersonationService,
|
|
|
|
private readonly impersonationService: ImpersonationService,
|
|
|
|
private readonly portfolioService: PortfolioService,
|
|
|
|
private readonly portfolioService: PortfolioService,
|
|
|
|
@Inject(REQUEST) private readonly request: RequestWithUser
|
|
|
|
@Inject(REQUEST) private readonly request: RequestWithUser
|
|
|
@ -84,13 +88,22 @@ export class AccountController {
|
|
|
|
@Get()
|
|
|
|
@Get()
|
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
|
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
|
|
|
|
@UseInterceptors(RedactValuesInResponseInterceptor)
|
|
|
|
@UseInterceptors(RedactValuesInResponseInterceptor)
|
|
|
|
|
|
|
|
@UseInterceptors(TransformDataSourceInRequestInterceptor)
|
|
|
|
public async getAllAccounts(
|
|
|
|
public async getAllAccounts(
|
|
|
|
@Headers(HEADER_KEY_IMPERSONATION.toLowerCase()) impersonationId
|
|
|
|
@Headers(HEADER_KEY_IMPERSONATION.toLowerCase()) impersonationId,
|
|
|
|
|
|
|
|
@Query('dataSource') filterByDataSource?: string,
|
|
|
|
|
|
|
|
@Query('symbol') filterBySymbol?: string
|
|
|
|
): Promise<Accounts> {
|
|
|
|
): Promise<Accounts> {
|
|
|
|
const impersonationUserId =
|
|
|
|
const impersonationUserId =
|
|
|
|
await this.impersonationService.validateImpersonationId(impersonationId);
|
|
|
|
await this.impersonationService.validateImpersonationId(impersonationId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filters = this.apiService.buildFiltersFromQueryParams({
|
|
|
|
|
|
|
|
filterByDataSource,
|
|
|
|
|
|
|
|
filterBySymbol
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return this.portfolioService.getAccountsWithAggregations({
|
|
|
|
return this.portfolioService.getAccountsWithAggregations({
|
|
|
|
|
|
|
|
filters,
|
|
|
|
userId: impersonationUserId || this.request.user.id,
|
|
|
|
userId: impersonationUserId || this.request.user.id,
|
|
|
|
withExcludedAccounts: true
|
|
|
|
withExcludedAccounts: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|