From 6167f105fe073edd37c05397a1e089abb5872cb0 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 21 Jan 2024 10:27:10 +0100 Subject: [PATCH] Refactoring (#2897) --- .../src/app/portfolio/portfolio-calculator.ts | 12 ++++++++---- apps/api/src/app/portfolio/portfolio.service.ts | 16 ++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts index 8168e2bc2..c072963d2 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -79,7 +79,9 @@ export class PortfolioCalculator { this.exchangeRateDataService = exchangeRateDataService; this.orders = orders; - this.orders.sort((a, b) => a.date?.localeCompare(b.date)); + this.orders.sort((a, b) => { + return a.date?.localeCompare(b.date); + }); } public computeTransactionPoints() { @@ -150,7 +152,9 @@ export class PortfolioCalculator { (transactionPointItem) => transactionPointItem.symbol !== order.symbol ); newItems.push(currentTransactionPointItem); - newItems.sort((a, b) => a.symbol?.localeCompare(b.symbol)); + newItems.sort((a, b) => { + return a.symbol?.localeCompare(b.symbol); + }); if (lastDate !== currentDate || lastTransactionPoint === null) { lastTransactionPoint = { date: currentDate, @@ -767,8 +771,8 @@ export class PortfolioCalculator { } } - return sortBy(investments, (investment) => { - return investment.date; + return sortBy(investments, ({ date }) => { + return date; }); } diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index bbd81a501..359ec0079 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -349,8 +349,8 @@ export class PortfolioService { } } - investments = sortBy(investments, (investment) => { - return investment.date; + investments = sortBy(investments, ({ date }) => { + return date; }); const startDate = this.getStartDate( @@ -765,9 +765,9 @@ export class PortfolioService { const currentPositions = await portfolioCalculator.getCurrentPositions(portfolioStart); - const position = currentPositions.positions.find( - (item) => item.symbol === aSymbol - ); + const position = currentPositions.positions.find(({ symbol }) => { + return symbol === aSymbol; + }); if (position) { const { @@ -2146,9 +2146,9 @@ export class PortfolioService { } ); - historicalDataItems.sort( - (a, b) => new Date(a.date).getTime() - new Date(b.date).getTime() - ); + historicalDataItems.sort((a, b) => { + return new Date(a.date).getTime() - new Date(b.date).getTime(); + }); return historicalDataItems; }