From 284aad9cd6c2755138b09854975fe5572678a893 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sun, 1 Aug 2021 17:53:13 +0200 Subject: [PATCH] Eliminate name from timeline position Get the name from the symbolProfileService instead --- .../transaction-point-symbol.interface.ts | 1 - apps/api/src/app/core/portfolio-calculator.ts | 7 ++----- apps/api/src/app/order/order.controller.ts | 5 +++++ apps/api/src/app/portfolio/portfolio.service.ts | 17 +++++++++++++++-- .../transactions-table.component.html | 7 ++++++- .../interfaces/timeline-position.interface.ts | 1 - 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts b/apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts index acd1f923c..0cf66083c 100644 --- a/apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts +++ b/apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts @@ -5,7 +5,6 @@ export interface TransactionPointSymbol { currency: Currency; firstBuyDate: string; investment: Big; - name: string; quantity: Big; symbol: string; transactionCount: number; diff --git a/apps/api/src/app/core/portfolio-calculator.ts b/apps/api/src/app/core/portfolio-calculator.ts index 3ff1f4ba3..0af578c30 100644 --- a/apps/api/src/app/core/portfolio-calculator.ts +++ b/apps/api/src/app/core/portfolio-calculator.ts @@ -23,8 +23,7 @@ import { isAfter, isBefore, max, - min, - subDays + min } from 'date-fns'; import { flatten } from 'lodash'; @@ -60,7 +59,6 @@ export class PortfolioCalculator { .mul(order.quantity) .mul(factor) .add(oldAccumulatedSymbol.investment), - name: order.name, quantity: order.quantity .mul(factor) .plus(oldAccumulatedSymbol.quantity), @@ -72,7 +70,6 @@ export class PortfolioCalculator { currency: order.currency, firstBuyDate: order.date, investment: unitPrice.mul(order.quantity).mul(factor), - name: order.name, quantity: order.quantity.mul(factor), symbol: order.symbol, transactionCount: 1 @@ -265,6 +262,7 @@ export class PortfolioCalculator { } const positions: TimelinePosition[] = []; + for (const item of lastTransactionPoint.items) { const marketValue = marketSymbolMap[todayString]?.[item.symbol]; const isValid = invalidSymbols.indexOf(item.symbol) === -1; @@ -281,7 +279,6 @@ export class PortfolioCalculator { : null, investment: item.investment, marketPrice: marketValue?.toNumber() ?? null, - name: item.name, quantity: item.quantity, symbol: item.symbol, transactionCount: item.transactionCount diff --git a/apps/api/src/app/order/order.controller.ts b/apps/api/src/app/order/order.controller.ts index 5671a5c9f..6e7a15026 100644 --- a/apps/api/src/app/order/order.controller.ts +++ b/apps/api/src/app/order/order.controller.ts @@ -80,6 +80,11 @@ export class OrderController { include: { Platform: true } + }, + SymbolProfile: { + select: { + name: true + } } }, orderBy: { date: 'desc' }, diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 68ea64ad2..6ac630b7c 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -239,7 +239,7 @@ export class PortfolioService { investment: item.investment.toNumber(), marketPrice: item.marketPrice, marketState: dataProviderResponse.marketState, - name: item.name, + name: symbolProfile.name, quantity: item.quantity.toNumber(), sectors: symbolProfile.sectors, symbol: item.symbol, @@ -438,6 +438,19 @@ export class PortfolioService { startDate ); + const symbols = currentPositions.positions.map( + (position) => position.symbol + ); + + const [symbolProfiles] = await Promise.all([ + this.symbolProfileService.getSymbolProfiles(symbols) + ]); + + const symbolProfileMap: { [symbol: string]: EnhancedSymbolProfile } = {}; + for (const symbolProfile of symbolProfiles) { + symbolProfileMap[symbolProfile.symbol] = symbolProfile; + } + return { hasErrors: currentPositions.hasErrors, positions: currentPositions.positions.map((position) => { @@ -448,7 +461,7 @@ export class PortfolioService { grossPerformancePercentage: position.grossPerformancePercentage?.toNumber() ?? null, investment: new Big(position.investment).toNumber(), - name: position.name, + name: symbolProfileMap[position.symbol].name, quantity: new Big(position.quantity).toNumber() }; }) diff --git a/apps/client/src/app/components/transactions-table/transactions-table.component.html b/apps/client/src/app/components/transactions-table/transactions-table.component.html index bdb670d71..6cf45b552 100644 --- a/apps/client/src/app/components/transactions-table/transactions-table.component.html +++ b/apps/client/src/app/components/transactions-table/transactions-table.component.html @@ -258,7 +258,12 @@ diff --git a/libs/common/src/lib/interfaces/timeline-position.interface.ts b/libs/common/src/lib/interfaces/timeline-position.interface.ts index 4fb306332..533c09a04 100644 --- a/libs/common/src/lib/interfaces/timeline-position.interface.ts +++ b/libs/common/src/lib/interfaces/timeline-position.interface.ts @@ -9,7 +9,6 @@ export interface TimelinePosition { grossPerformancePercentage: Big; investment: Big; marketPrice: number; - name: string; quantity: Big; symbol: string; transactionCount: number;