Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Bugfix/force reload accounts of user after change (#994)

Thomas Kaul2abe399ebd71
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93be00b6af..723fd8aac8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- Reloaded the accounts of a user after creating, editing or deleting one
- Excluded empty items in the activities filter
## 1.156.0 - 05.06.2022
diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts
index d0c30386e5..f3a0cab93d 100644
--- a/apps/api/src/app/user/user.service.ts
+++ b/apps/api/src/app/user/user.service.ts
@@ -12,6 +12,7 @@ import {
} from '@ghostfolio/common/permissions';
import { Injectable } from '@nestjs/common';
import { Prisma, Role, User, ViewMode } from '@prisma/client';
+import { sortBy } from 'lodash';
import { UserSettingsParams } from './interfaces/user-settings-params.interface';
import { UserSettings } from './interfaces/user-settings.interface';
@@ -185,6 +186,9 @@ export class UserService {
}
}
+ user.Account = sortBy(user.Account, (account) => {
+ return account.name;
+ });
user.permissions = currentPermissions.sort();
return user;
diff --git a/apps/client/src/app/pages/accounts/accounts-page.component.ts b/apps/client/src/app/pages/accounts/accounts-page.component.ts
index 60eb1463b2..624c2d3db1 100644
--- a/apps/client/src/app/pages/accounts/accounts-page.component.ts
+++ b/apps/client/src/app/pages/accounts/accounts-page.component.ts
@@ -133,6 +133,11 @@ export class AccountsPageComponent implements OnDestroy, OnInit {
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe({
next: () => {
+ this.userService
+ .get(true)
+ .pipe(takeUntil(this.unsubscribeSubject))
+ .subscribe();
+
this.fetchAccounts();
}
});
@@ -179,6 +184,11 @@ export class AccountsPageComponent implements OnDestroy, OnInit {
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe({
next: () => {
+ this.userService
+ .get(true)
+ .pipe(takeUntil(this.unsubscribeSubject))
+ .subscribe();
+
this.fetchAccounts();
}
});
@@ -220,6 +230,11 @@ export class AccountsPageComponent implements OnDestroy, OnInit {
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe({
next: () => {
+ this.userService
+ .get(true)
+ .pipe(takeUntil(this.unsubscribeSubject))
+ .subscribe();
+
this.fetchAccounts();
}
});
diff --git a/apps/client/src/app/services/user/user-store.actions.ts b/apps/client/src/app/services/user/user-store.actions.ts
index cbacd70d05..15dc555a49 100644
--- a/apps/client/src/app/services/user/user-store.actions.ts
+++ b/apps/client/src/app/services/user/user-store.actions.ts
@@ -1,4 +1,5 @@
export enum UserStoreActions {
GetUser = 'GET_USER',
+ Initialize = 'INITIALIZE',
RemoveUser = 'REMOVE_USER'
}
diff --git a/apps/client/src/app/services/user/user.service.ts b/apps/client/src/app/services/user/user.service.ts
index 2e66525919..79c15e085f 100644
--- a/apps/client/src/app/services/user/user.service.ts
+++ b/apps/client/src/app/services/user/user.service.ts
@@ -16,13 +16,13 @@ export class UserService extends ObservableStore<UserStoreState> {
public constructor(private http: HttpClient) {
super({ trackStateHistory: true });
- this.setState({ user: undefined }, 'INIT_STATE');
+ this.setState({ user: undefined }, UserStoreActions.Initialize);
}
- public get() {
+ public get(force = false) {
const state = this.getState();
- if (state?.user) {
+ if (state?.user && force !== true) {
// Get from cache
return of(state.user);
} else {