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) { if (currentDate) {
investments.push({ 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 investment: investmentByGroup
}); });
} }
@ -520,10 +526,10 @@ export class PortfolioCalculator {
// Store current group (latest order) // Store current group (latest order)
investments.push({ investments.push({
date: format( date: format(
set( set(currentDate, {
currentDate, date: 1,
groupBy === 'month' ? { date: 1 } : { date: 1, month: 1 } month: groupBy === 'year' ? 0 : currentDate.getMonth()
), }),
DATE_FORMAT DATE_FORMAT
), ),
investment: investmentByGroup investment: investmentByGroup

24
apps/api/src/app/portfolio/portfolio.service.ts

@ -294,10 +294,10 @@ export class PortfolioService {
// Add investment of current group // Add investment of current group
const dateOfCurrentGroup = format( const dateOfCurrentGroup = format(
set( set(new Date(), {
new Date(), date: 1,
groupBy === 'month' ? { date: 1 } : { date: 1, month: 1 } month: groupBy === 'year' ? 0 : new Date().getMonth()
), }),
DATE_FORMAT DATE_FORMAT
); );
const investmentOfCurrentGroup = investments.filter(({ date }) => { const investmentOfCurrentGroup = investments.filter(({ date }) => {
@ -1296,10 +1296,10 @@ export class PortfolioService {
if (currentDate) { if (currentDate) {
dividends.push({ dividends.push({
date: format( date: format(
set( set(currentDate, {
currentDate, date: 1,
groupBy === 'month' ? { date: 1 } : { date: 1, month: 1 } month: groupBy === 'year' ? 0 : currentDate.getMonth()
), }),
DATE_FORMAT DATE_FORMAT
), ),
investment: investmentByGroup investment: investmentByGroup
@ -1314,10 +1314,10 @@ export class PortfolioService {
// Store current month (latest order) // Store current month (latest order)
dividends.push({ dividends.push({
date: format( date: format(
set( set(currentDate, {
currentDate, date: 1,
groupBy === 'month' ? { date: 1 } : { date: 1, month: 1 } month: groupBy === 'year' ? 0 : currentDate.getMonth()
), }),
DATE_FORMAT DATE_FORMAT
), ),
investment: investmentByGroup investment: investmentByGroup

Loading…
Cancel
Save