diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index b71f7c921..ebad1a5c4 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1153,7 +1153,19 @@ export class PortfolioService { netWorth, totalInvestment, valueWithCurrencyEffect - } = last(chart); + } = + chart?.length > 0 + ? last(chart) + : { + grossPerformancePercent: 0, + netPerformance: 0, + netPerformanceInPercentage: 0, + netPerformanceInPercentageWithCurrencyEffect: 0, + netPerformanceWithCurrencyEffect: 0, + netWorth: 0, + totalInvestment: 0, + valueWithCurrencyEffect: 0 + }; return { chart, diff --git a/apps/api/src/app/user/user.controller.ts b/apps/api/src/app/user/user.controller.ts index 7cd2002bd..f826abe1d 100644 --- a/apps/api/src/app/user/user.controller.ts +++ b/apps/api/src/app/user/user.controller.ts @@ -144,6 +144,11 @@ export class UserController { ); } + const haveFiltersChanged = + 'filters.accounts' in data || + 'filters.assetClasses' in data || + 'filters.tags' in data; + const userSettings: UserSettings = { ...(this.request.user.Settings.settings), ...data @@ -157,6 +162,7 @@ export class UserController { return this.userService.updateUserSetting({ userSettings, + emitPortfolioChangedEvent: haveFiltersChanged, userId: this.request.user.id }); } diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index c87fdf1aa..9917f6a00 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -421,9 +421,11 @@ export class UserService { } public async updateUserSetting({ + emitPortfolioChangedEvent, userId, userSettings }: { + emitPortfolioChangedEvent: boolean; userId: string; userSettings: UserSettings; }) { @@ -444,13 +446,14 @@ export class UserService { } }); - // TODO: Handle changes in filters? - // this.eventEmitter.emit( - // PortfolioChangedEvent.getName(), - // new PortfolioChangedEvent({ - // userId - // }) - // ); + if (emitPortfolioChangedEvent) { + this.eventEmitter.emit( + PortfolioChangedEvent.getName(), + new PortfolioChangedEvent({ + userId + }) + ); + } return settings; } diff --git a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.html b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.html index a814a19a8..9f55250ec 100644 --- a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.html +++ b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.html @@ -20,6 +20,7 @@ +
diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.ts index eb0fce202..689150b68 100644 --- a/libs/common/src/lib/helper.ts +++ b/libs/common/src/lib/helper.ts @@ -350,7 +350,11 @@ export function isDerivedCurrency(aCurrency: string) { }); } -export function parseDate(date: string): Date | null { +export function parseDate(date: string): Date { + if (!date) { + return undefined; + } + // Transform 'yyyyMMdd' format to supported format by parse function if (date?.length === 8) { const match = date.match(/^(\d{4})(\d{2})(\d{2})$/);