Browse Source

Fix emergency fund for user with impersonation id

pull/749/head
Thomas 3 years ago
parent
commit
092f76edb2
  1. 10
      apps/api/src/app/portfolio/portfolio.service-new.ts
  2. 10
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 2
      apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html

10
apps/api/src/app/portfolio/portfolio.service-new.ts

@ -302,7 +302,6 @@ export class PortfolioServiceNew {
aDateRange: DateRange = 'max' aDateRange: DateRange = 'max'
): Promise<PortfolioDetails & { hasErrors: boolean }> { ): Promise<PortfolioDetails & { hasErrors: boolean }> {
const userId = await this.getUserId(aImpersonationId, aUserId); const userId = await this.getUserId(aImpersonationId, aUserId);
const user = await this.userService.user({ id: userId }); const user = await this.userService.user({ id: userId });
const emergencyFund = new Big( const emergencyFund = new Big(
@ -896,6 +895,7 @@ export class PortfolioServiceNew {
public async getSummary(aImpersonationId: string): Promise<PortfolioSummary> { public async getSummary(aImpersonationId: string): Promise<PortfolioSummary> {
const userCurrency = this.request.user.Settings.currency; const userCurrency = this.request.user.Settings.currency;
const userId = await this.getUserId(aImpersonationId, this.request.user.id); const userId = await this.getUserId(aImpersonationId, this.request.user.id);
const user = await this.userService.user({ id: userId });
const performanceInformation = await this.getPerformance(aImpersonationId); const performanceInformation = await this.getPerformance(aImpersonationId);
@ -908,9 +908,9 @@ export class PortfolioServiceNew {
userId userId
}); });
const dividend = this.getDividend(orders).toNumber(); const dividend = this.getDividend(orders).toNumber();
const emergencyFund = const emergencyFund = new Big(
(this.request.user?.Settings?.settings as UserSettings)?.emergencyFund ?? (user.Settings?.settings as UserSettings)?.emergencyFund ?? 0
0; );
const fees = this.getFees(orders).toNumber(); const fees = this.getFees(orders).toNumber();
const firstOrderDate = orders[0]?.date; const firstOrderDate = orders[0]?.date;
const items = this.getItems(orders).toNumber(); const items = this.getItems(orders).toNumber();
@ -946,7 +946,6 @@ export class PortfolioServiceNew {
annualizedPerformancePercent, annualizedPerformancePercent,
cash, cash,
dividend, dividend,
emergencyFund,
fees, fees,
firstOrderDate, firstOrderDate,
items, items,
@ -954,6 +953,7 @@ export class PortfolioServiceNew {
totalBuy, totalBuy,
totalSell, totalSell,
committedFunds: committedFunds.toNumber(), committedFunds: committedFunds.toNumber(),
emergencyFund: emergencyFund.toNumber(),
ordersCount: orders.filter((order) => { ordersCount: orders.filter((order) => {
return order.type === 'BUY' || order.type === 'SELL'; return order.type === 'BUY' || order.type === 'SELL';
}).length }).length

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

@ -293,7 +293,6 @@ export class PortfolioService {
aDateRange: DateRange = 'max' aDateRange: DateRange = 'max'
): Promise<PortfolioDetails & { hasErrors: boolean }> { ): Promise<PortfolioDetails & { hasErrors: boolean }> {
const userId = await this.getUserId(aImpersonationId, aUserId); const userId = await this.getUserId(aImpersonationId, aUserId);
const user = await this.userService.user({ id: userId }); const user = await this.userService.user({ id: userId });
const emergencyFund = new Big( const emergencyFund = new Big(
@ -874,6 +873,7 @@ export class PortfolioService {
public async getSummary(aImpersonationId: string): Promise<PortfolioSummary> { public async getSummary(aImpersonationId: string): Promise<PortfolioSummary> {
const userCurrency = this.request.user.Settings.currency; const userCurrency = this.request.user.Settings.currency;
const userId = await this.getUserId(aImpersonationId, this.request.user.id); const userId = await this.getUserId(aImpersonationId, this.request.user.id);
const user = await this.userService.user({ id: userId });
const performanceInformation = await this.getPerformance(aImpersonationId); const performanceInformation = await this.getPerformance(aImpersonationId);
@ -886,9 +886,9 @@ export class PortfolioService {
userId userId
}); });
const dividend = this.getDividend(orders).toNumber(); const dividend = this.getDividend(orders).toNumber();
const emergencyFund = const emergencyFund = new Big(
(this.request.user?.Settings?.settings as UserSettings)?.emergencyFund ?? (user.Settings?.settings as UserSettings)?.emergencyFund ?? 0
0; );
const fees = this.getFees(orders).toNumber(); const fees = this.getFees(orders).toNumber();
const firstOrderDate = orders[0]?.date; const firstOrderDate = orders[0]?.date;
const items = this.getItems(orders).toNumber(); const items = this.getItems(orders).toNumber();
@ -908,7 +908,6 @@ export class PortfolioService {
...performanceInformation.performance, ...performanceInformation.performance,
cash, cash,
dividend, dividend,
emergencyFund,
fees, fees,
firstOrderDate, firstOrderDate,
items, items,
@ -918,6 +917,7 @@ export class PortfolioService {
annualizedPerformancePercent: annualizedPerformancePercent:
performanceInformation.performance.annualizedPerformancePercent, performanceInformation.performance.annualizedPerformancePercent,
committedFunds: committedFunds.toNumber(), committedFunds: committedFunds.toNumber(),
emergencyFund: emergencyFund.toNumber(),
ordersCount: orders.filter((order) => { ordersCount: orders.filter((order) => {
return order.type === 'BUY' || order.type === 'SELL'; return order.type === 'BUY' || order.type === 'SELL';
}).length }).length

2
apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html

@ -140,7 +140,7 @@
<ion-icon <ion-icon
*ngIf="hasPermissionToUpdateUserSettings && !isLoading" *ngIf="hasPermissionToUpdateUserSettings && !isLoading"
class="mr-1 text-muted" class="mr-1 text-muted"
name="pencil-outline" name="ellipsis-horizontal-circle-outline"
></ion-icon> ></ion-icon>
<gf-value <gf-value
class="justify-content-end" class="justify-content-end"

Loading…
Cancel
Save