Browse Source

Fix setting month to jan for year groups

pull/1568/head
yksolanki9 3 years ago
parent
commit
79380eb4d2
  1. 16
      apps/api/src/app/portfolio/portfolio-calculator.ts
  2. 24
      apps/api/src/app/portfolio/portfolio.service.ts

16
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

24
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

Loading…
Cancel
Save