From 6aae0cc1e43dcb1db47e1ca5bc515c799d19066c Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 29 Jan 2023 09:58:05 +0100 Subject: [PATCH] Bugfix/fix issue with value in value redaction interceptor (#1627) * Fix issue with value in value redaction interceptor * Fix format of world map * Update changelog --- CHANGELOG.md | 2 ++ .../src/app/portfolio/portfolio.controller.ts | 7 +++-- .../src/app/portfolio/portfolio.service.ts | 8 +++--- .../position-detail-dialog.component.ts | 2 +- .../allocations/allocations-page.component.ts | 5 +++- .../analysis/analysis-page.component.ts | 7 +++-- .../app/pages/public/public-page.component.ts | 5 +++- .../src/app/pages/public/public-page.html | 1 + apps/client/src/app/services/data.service.ts | 28 ++++++++++++++++--- .../historical-data-item.interface.ts | 2 ++ .../portfolio-position.interface.ts | 3 +- .../portfolio-public-details.interface.ts | 1 + 12 files changed, 53 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 788abe8a..e102c5a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Improved the unit format (`%`) in the global heat map component of the public page - Improved the pricing page - Upgraded `Node.js` from version `16` to `18` (`Dockerfile`) - Upgraded `prisma` from version `4.8.0` to `4.9.0` @@ -21,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed the click of unknown accounts in the portfolio proportion chart component +- Fixed an issue with `value` in the value redaction interceptor for the impersonation mode ## 1.229.0 - 2023-01-21 diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index e607a5f9..79536219 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -131,7 +131,8 @@ export class PortfolioController { portfolioPosition.investment / totalInvestment; portfolioPosition.netPerformance = null; portfolioPosition.quantity = null; - portfolioPosition.value = portfolioPosition.value / totalValue; + portfolioPosition.valueInPercentage = + portfolioPosition.value / totalValue; } for (const [name, { current, original }] of Object.entries(accounts)) { @@ -322,7 +323,7 @@ export class PortfolioController { totalInvestment: new Big(totalInvestment) .div(performanceInformation.performance.totalInvestment) .toNumber(), - value: new Big(value) + valueInPercentage: new Big(value) .div(performanceInformation.performance.currentValue) .toNumber() }; @@ -437,7 +438,7 @@ export class PortfolioController { sectors: hasDetails ? portfolioPosition.sectors : [], symbol: portfolioPosition.symbol, url: portfolioPosition.url, - value: portfolioPosition.value / totalValue + valueInPercentage: portfolioPosition.value / totalValue }; } diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 3410be22..bce6de67 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -785,8 +785,8 @@ export class PortfolioService { historicalDataArray.push({ averagePrice: orders[0].unitPrice, date: firstBuyDate, - quantity: orders[0].quantity, - value: orders[0].unitPrice + marketPrice: orders[0].unitPrice, + quantity: orders[0].quantity }); } @@ -815,9 +815,9 @@ export class PortfolioService { historicalDataArray.push({ date, + marketPrice, averagePrice: currentAveragePrice, - quantity: currentQuantity, - value: marketPrice + quantity: currentQuantity }); maxPrice = Math.max(marketPrice ?? 0, maxPrice); diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts index 870971cb..fef9011d 100644 --- a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts +++ b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts @@ -111,7 +111,7 @@ export class PositionDetailDialog implements OnDestroy, OnInit { return { date: historicalDataItem.date, - value: historicalDataItem.value + value: historicalDataItem.marketPrice }; } ); diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts index 0dd32bf6..674498c9 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts @@ -21,6 +21,7 @@ import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { Market } from '@ghostfolio/common/types'; import { translate } from '@ghostfolio/ui/i18n'; import { Account, AssetClass, DataSource } from '@prisma/client'; +import { isNumber } from 'lodash'; import { DeviceDetectorService } from 'ngx-device-detector'; import { Subject } from 'rxjs'; import { distinctUntilChanged, switchMap, takeUntil } from 'rxjs/operators'; @@ -339,7 +340,9 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { dataSource: position.dataSource, name: position.name, symbol: prettifySymbol(symbol), - value: position.value + value: isNumber(position.value) + ? position.value + : position.valueInPercentage }; } diff --git a/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts b/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts index e91c13a1..2220f0ea 100644 --- a/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts +++ b/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -19,7 +19,7 @@ import { DateRange, GroupBy, ToggleOption } from '@ghostfolio/common/types'; import { translate } from '@ghostfolio/ui/i18n'; import { AssetClass, DataSource, SymbolProfile } from '@prisma/client'; import { differenceInDays } from 'date-fns'; -import { sortBy } from 'lodash'; +import { isNumber, sortBy } from 'lodash'; import { DeviceDetectorService } from 'ngx-device-detector'; import { Subject } from 'rxjs'; import { distinctUntilChanged, map, takeUntil } from 'rxjs/operators'; @@ -312,12 +312,13 @@ export class AnalysisPageComponent implements OnDestroy, OnInit { date, netPerformanceInPercentage, totalInvestment, - value + value, + valueInPercentage } of chart) { this.investments.push({ date, investment: totalInvestment }); this.performanceDataItems.push({ date, - value + value: isNumber(value) ? value : valueInPercentage }); this.performanceDataItemsInPercentage.push({ date, diff --git a/apps/client/src/app/pages/public/public-page.component.ts b/apps/client/src/app/pages/public/public-page.component.ts index fface381..f25c69da 100644 --- a/apps/client/src/app/pages/public/public-page.component.ts +++ b/apps/client/src/app/pages/public/public-page.component.ts @@ -9,6 +9,7 @@ import { } from '@ghostfolio/common/interfaces'; import { Market } from '@ghostfolio/common/types'; import { StatusCodes } from 'http-status-codes'; +import { isNumber } from 'lodash'; import { DeviceDetectorService } from 'ngx-device-detector'; import { EMPTY, Subject } from 'rxjs'; import { catchError, takeUntil } from 'rxjs/operators'; @@ -198,7 +199,9 @@ export class PublicPageComponent implements OnInit { this.symbols[prettifySymbol(symbol)] = { name: position.name, symbol: prettifySymbol(symbol), - value: position.value + value: isNumber(position.value) + ? position.value + : position.valueInPercentage }; } diff --git a/apps/client/src/app/pages/public/public-page.html b/apps/client/src/app/pages/public/public-page.html index 300b5e39..dd332db8 100644 --- a/apps/client/src/app/pages/public/public-page.html +++ b/apps/client/src/app/pages/public/public-page.html @@ -77,6 +77,7 @@ diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.ts index 67a3e18c..d4071cae 100644 --- a/apps/client/src/app/services/data.service.ts +++ b/apps/client/src/app/services/data.service.ts @@ -41,7 +41,7 @@ import { AccountWithValue, DateRange, GroupBy } from '@ghostfolio/common/types'; import { translate } from '@ghostfolio/ui/i18n'; import { DataSource, Order as OrderModel } from '@prisma/client'; import { format, parseISO } from 'date-fns'; -import { cloneDeep, groupBy } from 'lodash'; +import { cloneDeep, groupBy, isNumber } from 'lodash'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; @@ -299,6 +299,12 @@ export class DataService { ].dateOfFirstActivity ? parseISO(response.holdings[symbol].dateOfFirstActivity) : undefined; + + response.holdings[symbol].value = isNumber( + response.holdings[symbol].value + ) + ? response.holdings[symbol].value + : response.holdings[symbol].valueInPercentage; } } @@ -333,9 +339,23 @@ export class DataService { } public fetchPortfolioPublic(aId: string) { - return this.http.get( - `/api/v1/portfolio/public/${aId}` - ); + return this.http + .get(`/api/v1/portfolio/public/${aId}`) + .pipe( + map((response) => { + if (response.holdings) { + for (const symbol of Object.keys(response.holdings)) { + response.holdings[symbol].value = isNumber( + response.holdings[symbol].value + ) + ? response.holdings[symbol].value + : response.holdings[symbol].valueInPercentage; + } + } + + return response; + }) + ); } public fetchPortfolioReport() { diff --git a/libs/common/src/lib/interfaces/historical-data-item.interface.ts b/libs/common/src/lib/interfaces/historical-data-item.interface.ts index 59a53ee9..b8306ff8 100644 --- a/libs/common/src/lib/interfaces/historical-data-item.interface.ts +++ b/libs/common/src/lib/interfaces/historical-data-item.interface.ts @@ -2,9 +2,11 @@ export interface HistoricalDataItem { averagePrice?: number; date: string; grossPerformancePercent?: number; + marketPrice?: number; netPerformance?: number; netPerformanceInPercentage?: number; quantity?: number; totalInvestment?: number; value?: number; + valueInPercentage?: number; } diff --git a/libs/common/src/lib/interfaces/portfolio-position.interface.ts b/libs/common/src/lib/interfaces/portfolio-position.interface.ts index 126ffdab..2b7c6c48 100644 --- a/libs/common/src/lib/interfaces/portfolio-position.interface.ts +++ b/libs/common/src/lib/interfaces/portfolio-position.interface.ts @@ -30,5 +30,6 @@ export interface PortfolioPosition { symbol: string; type?: string; url?: string; - value: number; + value?: number; + valueInPercentage?: number; } diff --git a/libs/common/src/lib/interfaces/portfolio-public-details.interface.ts b/libs/common/src/lib/interfaces/portfolio-public-details.interface.ts index 2ba22a3d..7abc7f78 100644 --- a/libs/common/src/lib/interfaces/portfolio-public-details.interface.ts +++ b/libs/common/src/lib/interfaces/portfolio-public-details.interface.ts @@ -18,6 +18,7 @@ export interface PortfolioPublicDetails { | 'symbol' | 'url' | 'value' + | 'valueInPercentage' >; }; }