diff --git a/apps/api/src/app/portfolio/interfaces/portfolio-position-detail.interface.ts b/apps/api/src/app/portfolio/interfaces/portfolio-position-detail.interface.ts index 8cfd550af..99c7c6911 100644 --- a/apps/api/src/app/portfolio/interfaces/portfolio-position-detail.interface.ts +++ b/apps/api/src/app/portfolio/interfaces/portfolio-position-detail.interface.ts @@ -1,12 +1,8 @@ import { EnhancedSymbolProfile } from '@ghostfolio/api/services/interfaces/symbol-profile.interface'; import { OrderWithAccount } from '@ghostfolio/common/types'; -import { AssetClass, AssetSubClass } from '@prisma/client'; export interface PortfolioPositionDetail { - assetClass?: AssetClass; - assetSubClass?: AssetSubClass; averagePrice: number; - currency: string; firstBuyDate: string; grossPerformance: number; grossPerformancePercent: number; @@ -15,13 +11,11 @@ export interface PortfolioPositionDetail { marketPrice: number; maxPrice: number; minPrice: number; - name: string; netPerformance: number; netPerformancePercent: number; orders: OrderWithAccount[]; quantity: number; SymbolProfile: EnhancedSymbolProfile; - symbol: string; transactionCount: number; value: number; } diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index db4786527..38a083c75 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -344,6 +344,7 @@ export class PortfolioController { @Get('position/:dataSource/:symbol') @UseInterceptors(TransformDataSourceInRequestInterceptor) + @UseInterceptors(TransformDataSourceInResponseInterceptor) @UseGuards(AuthGuard('jwt')) public async getPosition( @Headers('impersonation-id') impersonationId: string, diff --git a/apps/api/src/app/portfolio/portfolio.service-new.ts b/apps/api/src/app/portfolio/portfolio.service-new.ts index d0db4169f..adeea5c91 100644 --- a/apps/api/src/app/portfolio/portfolio.service-new.ts +++ b/apps/api/src/app/portfolio/portfolio.service-new.ts @@ -417,7 +417,6 @@ export class PortfolioServiceNew { if (orders.length <= 0) { return { averagePrice: undefined, - currency: undefined, firstBuyDate: undefined, grossPerformance: undefined, grossPerformancePercent: undefined, @@ -426,21 +425,16 @@ export class PortfolioServiceNew { marketPrice: undefined, maxPrice: undefined, minPrice: undefined, - name: undefined, netPerformance: undefined, netPerformancePercent: undefined, orders: [], quantity: undefined, - symbol: aSymbol, SymbolProfile: undefined, transactionCount: undefined, value: undefined }; } - const assetClass = orders[0].SymbolProfile?.assetClass; - const assetSubClass = orders[0].SymbolProfile?.assetSubClass; - const name = orders[0].SymbolProfile?.name ?? ''; const positionCurrency = orders[0].currency; const [SymbolProfile] = await this.symbolProfileService.getSymbolProfiles([ aSymbol @@ -561,16 +555,12 @@ export class PortfolioServiceNew { } return { - assetClass, - assetSubClass, - currency, firstBuyDate, grossPerformance, investment, marketPrice, maxPrice, minPrice, - name, netPerformance, orders, SymbolProfile, @@ -581,7 +571,6 @@ export class PortfolioServiceNew { historicalData: historicalDataArray, netPerformancePercent: position.netPerformancePercentage?.toNumber(), quantity: quantity.toNumber(), - symbol: aSymbol, value: this.exchangeRateDataService.toCurrency( quantity.mul(marketPrice).toNumber(), currency, @@ -626,16 +615,12 @@ export class PortfolioServiceNew { } return { - assetClass, - assetSubClass, marketPrice, maxPrice, minPrice, - name, orders, SymbolProfile, averagePrice: 0, - currency: currentData[aSymbol]?.currency, firstBuyDate: undefined, grossPerformance: undefined, grossPerformancePercent: undefined, @@ -644,7 +629,6 @@ export class PortfolioServiceNew { netPerformance: undefined, netPerformancePercent: undefined, quantity: 0, - symbol: aSymbol, transactionCount: undefined, value: 0 }; diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 09f10cf84..0a164708c 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -405,7 +405,6 @@ export class PortfolioService { if (orders.length <= 0) { return { averagePrice: undefined, - currency: undefined, firstBuyDate: undefined, grossPerformance: undefined, grossPerformancePercent: undefined, @@ -414,21 +413,16 @@ export class PortfolioService { marketPrice: undefined, maxPrice: undefined, minPrice: undefined, - name: undefined, netPerformance: undefined, netPerformancePercent: undefined, orders: [], quantity: undefined, - symbol: aSymbol, SymbolProfile: undefined, transactionCount: undefined, value: undefined }; } - const assetClass = orders[0].SymbolProfile?.assetClass; - const assetSubClass = orders[0].SymbolProfile?.assetSubClass; - const name = orders[0].SymbolProfile?.name ?? ''; const positionCurrency = orders[0].currency; const [SymbolProfile] = await this.symbolProfileService.getSymbolProfiles([ aSymbol @@ -547,16 +541,12 @@ export class PortfolioService { } return { - assetClass, - assetSubClass, - currency, firstBuyDate, grossPerformance, investment, marketPrice, maxPrice, minPrice, - name, netPerformance, orders, SymbolProfile, @@ -566,7 +556,6 @@ export class PortfolioService { historicalData: historicalDataArray, netPerformancePercent: position.netPerformancePercentage.toNumber(), quantity: quantity.toNumber(), - symbol: aSymbol, value: this.exchangeRateDataService.toCurrency( quantity.mul(marketPrice).toNumber(), currency, @@ -611,16 +600,12 @@ export class PortfolioService { } return { - assetClass, - assetSubClass, marketPrice, maxPrice, minPrice, - name, orders, SymbolProfile, averagePrice: 0, - currency: currentData[aSymbol]?.currency, firstBuyDate: undefined, grossPerformance: undefined, grossPerformancePercent: undefined, @@ -629,7 +614,6 @@ export class PortfolioService { netPerformance: undefined, netPerformancePercent: undefined, quantity: 0, - symbol: aSymbol, transactionCount: undefined, value: 0 }; diff --git a/apps/api/src/interceptors/transform-data-source-in-response.interceptor.ts b/apps/api/src/interceptors/transform-data-source-in-response.interceptor.ts index 59e6c0e20..720f02b67 100644 --- a/apps/api/src/interceptors/transform-data-source-in-response.interceptor.ts +++ b/apps/api/src/interceptors/transform-data-source-in-response.interceptor.ts @@ -58,12 +58,25 @@ export class TransformDataSourceInResponseInterceptor }); } + if (data.orders) { + data.orders.map((order) => { + order.dataSource = encodeDataSource(order.dataSource); + return order; + }); + } + if (data.positions) { data.positions.map((position) => { position.dataSource = encodeDataSource(position.dataSource); return position; }); } + + if (data.SymbolProfile) { + data.SymbolProfile.dataSource = encodeDataSource( + data.SymbolProfile.dataSource + ); + } } return data; 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 0db04ef9d..db4cbf471 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 @@ -11,7 +11,7 @@ import { DataService } from '@ghostfolio/client/services/data.service'; import { DATE_FORMAT, downloadAsFile } from '@ghostfolio/common/helper'; import { OrderWithAccount } from '@ghostfolio/common/types'; import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface'; -import { AssetSubClass, SymbolProfile } from '@prisma/client'; +import { SymbolProfile } from '@prisma/client'; import { format, isSameMonth, isToday, parseISO } from 'date-fns'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -26,13 +26,11 @@ import { PositionDetailDialogParams } from './interfaces/interfaces'; styleUrls: ['./position-detail-dialog.component.scss'] }) export class PositionDetailDialog implements OnDestroy, OnInit { - public assetSubClass: AssetSubClass; public averagePrice: number; public benchmarkDataItems: LineChartItem[]; public countries: { [code: string]: { name: string; value: number }; }; - public currency: string; public firstBuyDate: string; public grossPerformance: number; public grossPerformancePercent: number; @@ -41,7 +39,6 @@ export class PositionDetailDialog implements OnDestroy, OnInit { public marketPrice: number; public maxPrice: number; public minPrice: number; - public name: string; public netPerformance: number; public netPerformancePercent: number; public orders: OrderWithAccount[]; @@ -50,7 +47,6 @@ export class PositionDetailDialog implements OnDestroy, OnInit { public sectors: { [name: string]: { name: string; value: number }; }; - public symbol: string; public SymbolProfile: SymbolProfile; public transactionCount: number; public value: number; @@ -73,9 +69,7 @@ export class PositionDetailDialog implements OnDestroy, OnInit { .pipe(takeUntil(this.unsubscribeSubject)) .subscribe( ({ - assetSubClass, averagePrice, - currency, firstBuyDate, grossPerformance, grossPerformancePercent, @@ -84,21 +78,17 @@ export class PositionDetailDialog implements OnDestroy, OnInit { marketPrice, maxPrice, minPrice, - name, netPerformance, netPerformancePercent, orders, quantity, - symbol, SymbolProfile, transactionCount, value }) => { - this.assetSubClass = assetSubClass; this.averagePrice = averagePrice; this.benchmarkDataItems = []; this.countries = {}; - this.currency = currency; this.firstBuyDate = firstBuyDate; this.grossPerformance = grossPerformance; this.grossPerformancePercent = grossPerformancePercent; @@ -119,13 +109,11 @@ export class PositionDetailDialog implements OnDestroy, OnInit { this.marketPrice = marketPrice; this.maxPrice = maxPrice; this.minPrice = minPrice; - this.name = name; this.netPerformance = netPerformance; this.netPerformancePercent = netPerformancePercent; this.orders = orders; this.quantity = quantity; this.sectors = {}; - this.symbol = symbol; this.SymbolProfile = SymbolProfile; this.transactionCount = transactionCount; this.value = value; @@ -195,7 +183,7 @@ export class PositionDetailDialog implements OnDestroy, OnInit { if (Number.isInteger(this.quantity)) { this.quantityPrecision = 0; - } else if (assetSubClass === 'CRYPTOCURRENCY') { + } else if (this.SymbolProfile?.assetSubClass === 'CRYPTOCURRENCY') { if (this.quantity < 1) { this.quantityPrecision = 7; } else if (this.quantity < 1000) { @@ -225,7 +213,7 @@ export class PositionDetailDialog implements OnDestroy, OnInit { .subscribe((data) => { downloadAsFile( data, - `ghostfolio-export-${this.symbol}-${format( + `ghostfolio-export-${this.SymbolProfile?.symbol}-${format( parseISO(data.meta.date), 'yyyyMMddHHmm' )}.json`, diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html index 9388c7a8a..74c679771 100644 --- a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html +++ b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html @@ -2,7 +2,7 @@ mat-dialog-title position="center" [deviceType]="data.deviceType" - [title]="name ?? symbol" + [title]="SymbolProfile?.name ?? SymbolProfile?.symbol" (closeButtonClicked)="onClose()" > @@ -55,7 +55,7 @@ @@ -64,7 +64,7 @@ @@ -73,7 +73,7 @@