From 79380eb4d2a16273a0d5aa2ad8f786086e1f3e4a Mon Sep 17 00:00:00 2001 From: yksolanki9 Date: Mon, 2 Jan 2023 20:41:09 +0530 Subject: [PATCH] Fix setting month to jan for year groups --- .../src/app/portfolio/portfolio-calculator.ts | 16 +++++++++---- .../src/app/portfolio/portfolio.service.ts | 24 +++++++++---------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts index 6225ae787..48f1e7507 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -505,7 +505,13 @@ export class PortfolioCalculator { if (currentDate) { investments.push({ - date: format(set(currentDate, { date: 1 }), DATE_FORMAT), + date: format( + set(currentDate, { + date: 1, + month: groupBy === 'year' ? 0 : currentDate.getMonth() + }), + DATE_FORMAT + ), investment: investmentByGroup }); } @@ -520,10 +526,10 @@ export class PortfolioCalculator { // Store current group (latest order) investments.push({ date: format( - set( - currentDate, - groupBy === 'month' ? { date: 1 } : { date: 1, month: 1 } - ), + set(currentDate, { + date: 1, + month: groupBy === 'year' ? 0 : currentDate.getMonth() + }), DATE_FORMAT ), investment: investmentByGroup diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index e00de76e4..26c087d1d 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -294,10 +294,10 @@ export class PortfolioService { // Add investment of current group const dateOfCurrentGroup = format( - set( - new Date(), - groupBy === 'month' ? { date: 1 } : { date: 1, month: 1 } - ), + set(new Date(), { + date: 1, + month: groupBy === 'year' ? 0 : new Date().getMonth() + }), DATE_FORMAT ); const investmentOfCurrentGroup = investments.filter(({ date }) => { @@ -1296,10 +1296,10 @@ export class PortfolioService { if (currentDate) { dividends.push({ date: format( - set( - currentDate, - groupBy === 'month' ? { date: 1 } : { date: 1, month: 1 } - ), + set(currentDate, { + date: 1, + month: groupBy === 'year' ? 0 : currentDate.getMonth() + }), DATE_FORMAT ), investment: investmentByGroup @@ -1314,10 +1314,10 @@ export class PortfolioService { // Store current month (latest order) dividends.push({ date: format( - set( - currentDate, - groupBy === 'month' ? { date: 1 } : { date: 1, month: 1 } - ), + set(currentDate, { + date: 1, + month: groupBy === 'year' ? 0 : currentDate.getMonth() + }), DATE_FORMAT ), investment: investmentByGroup