Browse Source

Refactoring

pull/1568/head
Thomas 3 years ago
parent
commit
8330c359f7
  1. 24
      apps/api/src/app/portfolio/portfolio.service.ts
  2. 6
      apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts

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

@ -236,7 +236,7 @@ export class PortfolioService {
}); });
if (groupBy) { if (groupBy) {
dividends = this.getDividendsByGroup({ aDividends: dividends, groupBy }); dividends = this.getDividendsByGroup({ dividends, groupBy });
} }
const startDate = this.getStartDate( const startDate = this.getStartDate(
@ -1270,21 +1270,21 @@ export class PortfolioService {
} }
private getDividendsByGroup({ private getDividendsByGroup({
aDividends, dividends,
groupBy groupBy
}: { }: {
aDividends: InvestmentItem[]; dividends: InvestmentItem[];
groupBy: GroupBy; groupBy: GroupBy;
}): InvestmentItem[] { }): InvestmentItem[] {
if (aDividends.length === 0) { if (dividends.length === 0) {
return []; return [];
} }
const dividends = []; const dividendsByGroup: InvestmentItem[] = [];
let currentDate: Date; let currentDate: Date;
let investmentByGroup = new Big(0); let investmentByGroup = new Big(0);
for (const [index, dividend] of aDividends.entries()) { for (const [index, dividend] of dividends.entries()) {
if ( if (
isSameYear(parseDate(dividend.date), currentDate) && isSameYear(parseDate(dividend.date), currentDate) &&
(groupBy === 'year' || (groupBy === 'year' ||
@ -1297,7 +1297,7 @@ export class PortfolioService {
// New group: Store previous group and reset // New group: Store previous group and reset
if (currentDate) { if (currentDate) {
dividends.push({ dividendsByGroup.push({
date: format( date: format(
set(currentDate, { set(currentDate, {
date: 1, date: 1,
@ -1305,7 +1305,7 @@ export class PortfolioService {
}), }),
DATE_FORMAT DATE_FORMAT
), ),
investment: investmentByGroup investment: investmentByGroup.toNumber()
}); });
} }
@ -1313,9 +1313,9 @@ export class PortfolioService {
investmentByGroup = new Big(dividend.investment); investmentByGroup = new Big(dividend.investment);
} }
if (index === aDividends.length - 1) { if (index === dividends.length - 1) {
// Store current month (latest order) // Store current month (latest order)
dividends.push({ dividendsByGroup.push({
date: format( date: format(
set(currentDate, { set(currentDate, {
date: 1, date: 1,
@ -1323,12 +1323,12 @@ export class PortfolioService {
}), }),
DATE_FORMAT DATE_FORMAT
), ),
investment: investmentByGroup investment: investmentByGroup.toNumber()
}); });
} }
} }
return dividends; return dividendsByGroup;
} }
private getFees({ private getFees({

6
apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts

@ -93,12 +93,14 @@ export class AnalysisPageComponent implements OnDestroy, OnInit {
} }
get savingsRate() { get savingsRate() {
const savingsRate = const savingsRatePerMonth =
this.hasImpersonationId || this.user.settings.isRestrictedView this.hasImpersonationId || this.user.settings.isRestrictedView
? undefined ? undefined
: this.user?.settings?.savingsRate; : this.user?.settings?.savingsRate;
return this.mode === 'year' ? savingsRate * 12 : savingsRate; return this.mode === 'year'
? savingsRatePerMonth * 12
: savingsRatePerMonth;
} }
public ngOnInit() { public ngOnInit() {

Loading…
Cancel
Save