added dictionary instead of keys array

This commit is contained in:
Edi Cziszter 2021-12-10 17:31:35 +02:00
parent 80c8aebb7a
commit 035c868c81

View File

@ -3,7 +3,10 @@ import { GenericService, List, RequiredParam, Validate } from '@iqser/common-ui'
type UserAttributes = Record<string, List>;
const KEYS = ['Language', 'Dossier-Recent'];
const KEYS = {
language: 'Language',
dossierRecent: 'Dossier-Recent',
} as const;
@Injectable({
providedIn: 'root',
@ -30,13 +33,13 @@ export class UserPreferenceService extends GenericService<UserAttributes> {
}
async saveLastOpenedFileForDossier(dossierId: string, fileId: string): Promise<void> {
const key = `${KEYS[1]}-${dossierId}`;
const key = `${KEYS.dossierRecent}-${dossierId}`;
this.userAttributes[key] = [fileId];
await this.savePreferences([fileId], key).toPromise();
}
getLanguage(): string {
const key = KEYS[0];
const key = KEYS.language;
if (this.userAttributes[key]?.length > 0) {
return this.userAttributes[key][0];
}
@ -44,7 +47,7 @@ export class UserPreferenceService extends GenericService<UserAttributes> {
}
async saveLanguage(language: string): Promise<void> {
const key = KEYS[0];
const key = KEYS.language;
this.userAttributes[key] = [language];
await this.savePreferences([language], key).toPromise();
}