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