From 145f2063075660fa341af66de7a50440cb13fad7 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 22 May 2024 11:26:01 +0300 Subject: [PATCH] tidy up app have gone through all the TODO notes --- ui/src/app/account/login/login.component.ts | 3 +- ui/src/app/account/service/account.service.ts | 35 ++++++++----------- .../app/account/service/auth-jwt.service.ts | 13 ------- .../account/service/state-storage.service.ts | 21 ----------- .../member-info/member-info-edit.component.ts | 4 --- 5 files changed, 16 insertions(+), 60 deletions(-) diff --git a/ui/src/app/account/login/login.component.ts b/ui/src/app/account/login/login.component.ts index f8b06be60..4b36edbea 100644 --- a/ui/src/app/account/login/login.component.ts +++ b/ui/src/app/account/login/login.component.ts @@ -95,8 +95,7 @@ export class LoginComponent implements AfterViewInit, OnDestroy { } this.mfaSent = false }, - // TODO: review any type - error: (err) => { + error: () => { this.loginService.logout() this.authenticationError = true }, diff --git a/ui/src/app/account/service/account.service.ts b/ui/src/app/account/service/account.service.ts index 13945b1ad..32640b39a 100644 --- a/ui/src/app/account/service/account.service.ts +++ b/ui/src/app/account/service/account.service.ts @@ -1,17 +1,16 @@ import { Injectable } from '@angular/core' import { SessionStorageService } from 'ngx-webstorage' -import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http' -import { BehaviorSubject, EMPTY, Observable, Subject, catchError, map, of, takeUntil, tap } from 'rxjs' +import { HttpClient, HttpResponse } from '@angular/common/http' +import { BehaviorSubject, EMPTY, Observable, Subject, catchError, map, of, takeUntil } from 'rxjs' import { IAccount } from '../model/account.model' import { LanguageService } from 'src/app/shared/service/language.service' import { Router } from '@angular/router' -// TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service -//import { MSMemberService } from 'app/entities/member/member.service'; +import { MemberService } from 'src/app/member/service/member.service' @Injectable({ providedIn: 'root' }) export class AccountService { - // TODO: have unknown and offline instead of undefined and null + // TODO: have custom 'unknown' and 'offline' statuses instead of 'undefined' and 'null' private accountData = new BehaviorSubject(undefined) private isFetchingAccountData = false private stopFetchingAccountData = new Subject() @@ -21,9 +20,9 @@ export class AccountService { private languageService: LanguageService, private sessionStorage: SessionStorageService, private router: Router, - private http: HttpClient // TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service - ) //private memberService: MSMemberService - {} + private http: HttpClient, + private memberService: MemberService + ) {} private fetchAccountData() { this.isFetchingAccountData = true @@ -33,11 +32,10 @@ export class AccountService { }) .pipe( takeUntil(this.stopFetchingAccountData), - catchError((err) => { + catchError(() => { this.authenticated = false this.accountData.next(null) - // TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service - //this.memberService.memberData.next(undefined); + this.memberService.setMemberData(undefined) this.isFetchingAccountData = false return EMPTY }), @@ -51,8 +49,7 @@ export class AccountService { } this.accountData.next(account) } else { - // TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service - //this.memberService.memberData.next(undefined); + this.memberService.setMemberData(undefined) this.accountData.next(null) this.authenticated = false console.error('Invalid response:', response) @@ -69,7 +66,7 @@ export class AccountService { const headers = { 'Accept-Language': account.langKey } return this.http.post('/services/userservice/api/account', account, { observe: 'response', headers }).pipe( map((res: HttpResponse) => this.isSuccess(res)), - catchError((err) => { + catchError(() => { return of(false) }) ) @@ -85,7 +82,7 @@ export class AccountService { enableMfa(mfaSetup: any): Observable { return this.http.post('/services/userservice/api/account/mfa/on', mfaSetup, { observe: 'response' }).pipe( map((res: HttpResponse) => res.body), - catchError((err) => { + catchError(() => { console.error('error enabling mfa') return of(null) }) @@ -95,12 +92,11 @@ export class AccountService { disableMfa(): Observable { return this.http.post('/services/userservice/api/account/mfa/off', null, { observe: 'response' }).pipe( map((res: HttpResponse) => this.isSuccess(res)), - catchError((err) => { + catchError(() => { return of(false) }) ) } - // TODO: any - this seems to only be used for logging out (only ever receives null as arg) clearAccountData() { this.accountData.next(null) this.authenticated = false @@ -131,9 +127,8 @@ export class AccountService { getAccountData(force?: boolean): Observable { if (force) { - // TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service - //this.memberService.stopFetchingMemberData.next(); - //this.memberService.memberData.next(undefined); + this.memberService.stopFetchingMemberData.next(true) + this.memberService.setMemberData(undefined) this.stopFetchingAccountData.next(true) } if ((this.accountData.value === undefined && !this.isFetchingAccountData) || force) { diff --git a/ui/src/app/account/service/auth-jwt.service.ts b/ui/src/app/account/service/auth-jwt.service.ts index 637fafddd..674ffa3d2 100644 --- a/ui/src/app/account/service/auth-jwt.service.ts +++ b/ui/src/app/account/service/auth-jwt.service.ts @@ -15,19 +15,6 @@ export class AuthServerProvider { return this.http.post('/auth/login', credentials) } - // TODO: not being used? - /* loginWithToken(jwt, rememberMe) { - if (jwt) { - this.storeAuthenticationToken(jwt, rememberMe); - return Promise.resolve(jwt); - } else { - return Promise.reject('auth-jwt-service Promise reject'); // Put appropriate error message here - } - } - - storeAuthenticationToken(jwt, rememberMe) {} -*/ - logout(): Observable { return this.http.post('/auth/logout', null) } diff --git a/ui/src/app/account/service/state-storage.service.ts b/ui/src/app/account/service/state-storage.service.ts index c0877e46d..29857c254 100644 --- a/ui/src/app/account/service/state-storage.service.ts +++ b/ui/src/app/account/service/state-storage.service.ts @@ -13,12 +13,6 @@ export class StateStorageService { this.$sessionStorage.clear('previousState') } - // TODO: not being used? - /* storePreviousState(previousStateName, previousStateParams) { - const previousState = { name: previousStateName, params: previousStateParams }; - this.$sessionStorage.store('previousState', previousState); - } */ - getDestinationState() { return this.$sessionStorage.retrieve('destinationState') } @@ -30,19 +24,4 @@ export class StateStorageService { getUrl() { return this.$sessionStorage.retrieve('previousUrl') } - - // TODO: not being used? - /* storeDestinationState(destinationState, destinationStateParams, fromState) { - const destinationInfo = { - destination: { - name: destinationState.name, - data: destinationState.data - }, - params: destinationStateParams, - from: { - name: fromState.name - } - }; - this.$sessionStorage.store('destinationState', destinationInfo); - } */ } diff --git a/ui/src/app/home/member-info/member-info-edit.component.ts b/ui/src/app/home/member-info/member-info-edit.component.ts index c1e946d1a..fc43b0826 100644 --- a/ui/src/app/home/member-info/member-info-edit.component.ts +++ b/ui/src/app/home/member-info/member-info-edit.component.ts @@ -100,10 +100,6 @@ export class MemberInfoEditComponent implements OnInit, OnDestroy { .pipe(take(1)) .subscribe((countries) => { this.countries = countries - // TODO: redundant? remove - if (this.memberData) { - this.updateForm(this.memberData) - } }) this.editForm.valueChanges.subscribe(() => {