From 334f80b2fe740272d5bd081a15fc985cae7bd883 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Mon, 22 Nov 2021 20:35:01 +0100 Subject: [PATCH] Calculate min / max for the full portfolio --- apps/api/src/app/portfolio/portfolio.service.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 427ad1e1e..d3ef06db2 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -187,7 +187,10 @@ export class PortfolioService { DATE_FORMAT, new Date() ); - portfolioStart = this.getStartDate(aDateRange, portfolioStart); + + // Get start date for the full portfolio because of because of the + // min and max calculation + portfolioStart = this.getStartDate('max', portfolioStart); const timelineSpecification: TimelineSpecification[] = [ { @@ -226,10 +229,19 @@ export class PortfolioService { isAllTimeHigh = false; isAllTimeLow = false; } + + portfolioStart = this.getStartDate( + aDateRange, + parse(transactionPoints[0].date, DATE_FORMAT, new Date()) + ); + return { isAllTimeHigh, isAllTimeLow, - items + items: items.filter((item) => { + // Filter items of date range + return isBefore(portfolioStart, parseDate(item.date)); + }) }; }