From 9431a2ba9fd04bc51d64fc48f7a34d447e81c6c0 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sun, 26 Nov 2023 20:59:45 +0100 Subject: [PATCH] Refactoring --- .../src/app/portfolio/portfolio.service.ts | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 4659a563d..b5bc589e6 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -275,6 +275,13 @@ export class PortfolioService { includeDrafts: true }); + if (transactionPoints.length === 0) { + return { + investments: [], + streaks: { currentStreak: 0, longestStreak: 0 } + }; + } + const portfolioCalculator = new PortfolioCalculator({ currency: this.request.user.Settings.settings.baseCurrency, currentRateService: this.currentRateService, @@ -282,12 +289,6 @@ export class PortfolioService { }); portfolioCalculator.setTransactionPoints(transactionPoints); - if (transactionPoints.length === 0) { - return { - investments: [], - streaks: { currentStreak: 0, longestStreak: 0 } - }; - } let investments: InvestmentItem[]; @@ -975,12 +976,6 @@ export class PortfolioService { userId }); - const portfolioCalculator = new PortfolioCalculator({ - currency: this.request.user.Settings.settings.baseCurrency, - currentRateService: this.currentRateService, - orders: portfolioOrders - }); - if (transactionPoints?.length <= 0) { return { hasErrors: false, @@ -988,6 +983,12 @@ export class PortfolioService { }; } + const portfolioCalculator = new PortfolioCalculator({ + currency: this.request.user.Settings.settings.baseCurrency, + currentRateService: this.currentRateService, + orders: portfolioOrders + }); + portfolioCalculator.setTransactionPoints(transactionPoints); const portfolioStart = parseDate(transactionPoints[0].date); @@ -1380,6 +1381,14 @@ export class PortfolioService { userCurrency: string; userId: string; }): Promise { + if (transactionPoints.length === 0) { + return { + isAllTimeHigh: false, + isAllTimeLow: false, + items: [] + }; + } + userId = await this.getUserId(impersonationId, userId); const portfolioCalculator = new PortfolioCalculator({ @@ -1389,13 +1398,7 @@ export class PortfolioService { }); portfolioCalculator.setTransactionPoints(transactionPoints); - if (transactionPoints.length === 0) { - return { - isAllTimeHigh: false, - isAllTimeLow: false, - items: [] - }; - } + const endDate = new Date(); const portfolioStart = parseDate(transactionPoints[0].date);