diff options
Diffstat (limited to 'ufund-ui')
| -rw-r--r-- | ufund-ui/src/app/components/need-list/need-list.component.ts | 25 | 
1 files changed, 15 insertions, 10 deletions
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index 2bbacb0..66e53e8 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -3,6 +3,8 @@ import {Need} from '../../models/Need';  import {CupboardService} from '../../services/cupboard.service';  import { UsersService } from '../../services/users.service';  import { userType } from '../../models/User'; +import {AuthService} from '../../services/auth.service'; +import {catchError, of} from 'rxjs';  interface sortAlgo {    (a: Need,b: Need): number; @@ -72,7 +74,8 @@ export class NeedListComponent {    constructor(      private cupboardService: CupboardService, -    private usersService: UsersService +    private usersService: UsersService, +    private authService: AuthService    ) {}      refresh() { @@ -148,12 +151,12 @@ export class NeedListComponent {    }    isManager() { -    const type = this.usersService.getCurrentUser()?.type; +    const type = this.authService.getCurrentUser()?.type;      return type === ("MANAGER" as unknown as userType);    }    isHelper() { -    const type = this.usersService.getCurrentUser()?.type; +    const type = this.authService.getCurrentUser()?.type;      return type === ("HELPER" as unknown as userType);    } @@ -165,17 +168,19 @@ export class NeedListComponent {    }    add(need: Need) { -    const currentUser = this.usersService.getCurrentUser(); +    const currentUser = this.authService.getCurrentUser();      //console.log("get current user in angular:", currentUser)      if (currentUser) {        if (!currentUser.basket.includes(need.id)) {          currentUser.basket.push(need.id); -        this.usersService.updateUser(currentUser).subscribe(() => { -          this.usersService.refreshBasket(); -          error: (err: any) => { -            console.error(err); -          } -        }); +        this.usersService.updateUser(currentUser) +            .pipe(catchError((err, _) =>  { +                console.error(err); +                return of(); +            })) +            .subscribe(() => { +                this.usersService.refreshBasket(); +            });        } else {          window.alert("This need is already in your basket!")        }  | 
