diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2025-04-04 21:55:12 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2025-04-04 21:55:12 -0400 |
commit | b578584a1208178100bf90e8b06971772c7fc00f (patch) | |
tree | 6c2e5ee5fd3cc7e96e036704ebe3b1ba7cbfc9f5 /ufund-ui/src/app/services/users.service.ts | |
parent | 03431245f71385c5d641f66a7f63c1a22ab65210 (diff) | |
download | JellySolutions-b578584a1208178100bf90e8b06971772c7fc00f.tar.gz JellySolutions-b578584a1208178100bf90e8b06971772c7fc00f.tar.bz2 JellySolutions-b578584a1208178100bf90e8b06971772c7fc00f.zip |
Fix many bugs and code clean up
Diffstat (limited to 'ufund-ui/src/app/services/users.service.ts')
-rw-r--r-- | ufund-ui/src/app/services/users.service.ts | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 4080ebf..d23b59b 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; import {BehaviorSubject, catchError, firstValueFrom, Observable, of} from 'rxjs'; -import {User} from '../models/User'; +import {User, userType} from '../models/User'; import { Need } from '../models/Need'; import { CupboardService } from './cupboard.service'; import {AuthService} from './auth.service'; @@ -25,7 +25,9 @@ export class UsersService { private http: HttpClient, private cupboardService: CupboardService, private authService: AuthService - ) {} + ) { + authService.getCurrentUserSubject().subscribe(() => this.refreshBasket()) + } async createUser(username:string, password:string) { await firstValueFrom(this.http.post<User>(this.url, {username: username, password: password}, this.httpOptions())) @@ -71,4 +73,16 @@ export class UsersService { return this.basket; } + isManager() { + return this.authService.getCurrentUser()?.type === userType.MANAGER + } + + isHelper() { + return this.authService.getCurrentUser()?.type === userType.HELPER + } + + inBasket(basket: Need[] | null, need: Need) { + return basket?.map(r => r.id).includes(need.id); + } + } |