Ag Grid anpassungen
This commit is contained in:
@@ -17,9 +17,26 @@ export class ApiService {
|
||||
public cylinders: BehaviorSubject<ICylinder[]> = new BehaviorSubject<ICylinder[]>([]);
|
||||
|
||||
|
||||
public user: BehaviorSubject<IUser> = new BehaviorSubject<IUser>(null!);
|
||||
public settings: BehaviorSubject<Object> = new BehaviorSubject<Object>(null!);
|
||||
|
||||
|
||||
constructor() { }
|
||||
|
||||
getMe(): Promise<IUser> {
|
||||
return new Promise(resolve => {
|
||||
this.http.get<IUser>('/api/auth/me').subscribe({
|
||||
next: user => {
|
||||
this.user.next(user);
|
||||
resolve(user)
|
||||
},
|
||||
error: () => {
|
||||
resolve(null!)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
getAllUsers(): Observable<IUser[]> {
|
||||
return this.http.get<IUser[]>('/api/user');
|
||||
@@ -157,11 +174,44 @@ export class ApiService {
|
||||
return this.http.post<ICylinder>('api/cylinder', data);
|
||||
}
|
||||
|
||||
getSettings(): Observable<any> {
|
||||
return this.http.get('api/user/settings')
|
||||
private loadSettings(): Promise<Object> {
|
||||
return new Promise(resolve => {
|
||||
this.http.get('api/user/settings').subscribe({
|
||||
next: val => {
|
||||
this.settings.next(val);
|
||||
return resolve(val);
|
||||
},
|
||||
error: () => {
|
||||
this.toast.error("Einstellungen konnten nicht geladen werden");
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
updateSettings(settings: any): Observable<any> {
|
||||
return this.http.post('api/user/settings', settings)
|
||||
get userSettings(): Promise<Object> {
|
||||
if (!this.settings.value) {
|
||||
return this.loadSettings();
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
return resolve(this.settings.value);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
updateSettings(settings: any): Promise<boolean> {
|
||||
return new Promise(resolve => {
|
||||
this.http.post('api/user/settings', settings).subscribe({
|
||||
next: async () => {
|
||||
await this.loadSettings();
|
||||
this.toast.success('Einstellungen gespeichert')
|
||||
return resolve(true);
|
||||
},
|
||||
error: () => {
|
||||
this.toast.error("Fehler beim Speichern der Einstellungen");
|
||||
return resolve(false)
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user