From 5529fdc0ee3c1d9e28094dc792b3eebfb5dd9d2c Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:50:24 +0100 Subject: [PATCH] Move transaction points to constructor (#3202) --- .../src/app/portfolio/portfolio-calculator.ts | 12 +++++---- .../src/app/portfolio/portfolio.service.ts | 27 ++++++++----------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts index 438653fc6..d37a872c5 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -49,12 +49,14 @@ export class PortfolioCalculator { currency, currentRateService, exchangeRateDataService, - orders + orders, + transactionPoints }: { currency: string; currentRateService: CurrentRateService; exchangeRateDataService: ExchangeRateDataService; orders: PortfolioOrder[]; + transactionPoints?: TransactionPoint[]; }) { this.currency = currency; this.currentRateService = currentRateService; @@ -64,6 +66,10 @@ export class PortfolioCalculator { this.orders.sort((a, b) => { return a.date?.localeCompare(b.date); }); + + if (transactionPoints) { + this.transactionPoints = transactionPoints; + } } public computeTransactionPoints() { @@ -179,10 +185,6 @@ export class PortfolioCalculator { return this.transactionPoints; } - public setTransactionPoints(transactionPoints: TransactionPoint[]) { - this.transactionPoints = transactionPoints; - } - public async getChartData({ end = new Date(Date.now()), start, diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index f7d780b3d..061c4b8be 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -282,14 +282,13 @@ export class PortfolioService { } const portfolioCalculator = new PortfolioCalculator({ + transactionPoints, currency: this.request.user.Settings.settings.baseCurrency, currentRateService: this.currentRateService, exchangeRateDataService: this.exchangeRateDataService, orders: portfolioOrders }); - portfolioCalculator.setTransactionPoints(transactionPoints); - const { items } = await this.getChart({ dateRange, impersonationId, @@ -374,14 +373,13 @@ export class PortfolioService { }); const portfolioCalculator = new PortfolioCalculator({ + transactionPoints, currency: userCurrency, currentRateService: this.currentRateService, exchangeRateDataService: this.exchangeRateDataService, orders: portfolioOrders }); - portfolioCalculator.setTransactionPoints(transactionPoints); - const portfolioStart = parseDate( transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT) ); @@ -999,14 +997,13 @@ export class PortfolioService { } const portfolioCalculator = new PortfolioCalculator({ + transactionPoints, currency: this.request.user.Settings.settings.baseCurrency, currentRateService: this.currentRateService, exchangeRateDataService: this.exchangeRateDataService, orders: portfolioOrders }); - portfolioCalculator.setTransactionPoints(transactionPoints); - const portfolioStart = parseDate(transactionPoints[0].date); const startDate = this.getStartDate(dateRange, portfolioStart); const currentPositions = @@ -1165,13 +1162,6 @@ export class PortfolioService { types: withItems ? ['BUY', 'ITEM', 'SELL'] : ['BUY', 'SELL'] }); - const portfolioCalculator = new PortfolioCalculator({ - currency: userCurrency, - currentRateService: this.currentRateService, - exchangeRateDataService: this.exchangeRateDataService, - orders: portfolioOrders - }); - if (accountBalanceItems?.length <= 0 && transactionPoints?.length <= 0) { return { chart: [], @@ -1193,7 +1183,13 @@ export class PortfolioService { }; } - portfolioCalculator.setTransactionPoints(transactionPoints); + const portfolioCalculator = new PortfolioCalculator({ + transactionPoints, + currency: userCurrency, + currentRateService: this.currentRateService, + exchangeRateDataService: this.exchangeRateDataService, + orders: portfolioOrders + }); const portfolioStart = min( [ @@ -1318,14 +1314,13 @@ export class PortfolioService { }); const portfolioCalculator = new PortfolioCalculator({ + transactionPoints, currency: userCurrency, currentRateService: this.currentRateService, exchangeRateDataService: this.exchangeRateDataService, orders: portfolioOrders }); - portfolioCalculator.setTransactionPoints(transactionPoints); - const portfolioStart = parseDate( transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT) );