Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Move transaction points to constructor (#3202)
Thomas Kaul5529fdc0ee3c
diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.tsindex 438653fc6b..d37a872c56 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.tsindex f7d780b3d1..061c4b8be6 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));