diff options
| author | benal01 <bja4245@rit.edu> | 2025-04-05 13:22:58 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-05 13:22:58 -0400 | 
| commit | 0103ffc6f84d04433943c644ab759c1d04b5e681 (patch) | |
| tree | 1cd8fb31b849b4d5be00d4be0e3db92bbbafb5e1 /ufund-ui/src/app/services | |
| parent | 5a5d31896d79a736bce33b7d1aa7b3168ba308a9 (diff) | |
| parent | 04db6f32b249ffb17c571cd6b16c8c54397f0be4 (diff) | |
| download | JellySolutions-0103ffc6f84d04433943c644ab759c1d04b5e681.tar.gz JellySolutions-0103ffc6f84d04433943c644ab759c1d04b5e681.tar.bz2 JellySolutions-0103ffc6f84d04433943c644ab759c1d04b5e681.zip  | |
Merge pull request #27 from RIT-SWEN-261-02/need-list-abstraction
Need list abstraction
Diffstat (limited to '')
| -rw-r--r-- | ufund-ui/src/app/services/cupboard.service.ts | 4 | ||||
| -rw-r--r-- | ufund-ui/src/app/services/modal.service.ts | 25 | ||||
| -rw-r--r-- | ufund-ui/src/app/services/users.service.ts | 18 | 
3 files changed, 43 insertions, 4 deletions
diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts index 1060476..a87dee2 100644 --- a/ufund-ui/src/app/services/cupboard.service.ts +++ b/ufund-ui/src/app/services/cupboard.service.ts @@ -23,8 +23,8 @@ export class CupboardService {          private authService: AuthService      ) {} -    createNeed(need: Need): Observable<boolean> { -        return this.http.post<boolean>(this.url, need, this.httpOptions()) +    createNeed(need: Need): Observable<Need> { +        return this.http.post<Need>(this.url, need, this.httpOptions())      }      getNeeds(): Observable<Need[]> { diff --git a/ufund-ui/src/app/services/modal.service.ts b/ufund-ui/src/app/services/modal.service.ts new file mode 100644 index 0000000..04f2f3a --- /dev/null +++ b/ufund-ui/src/app/services/modal.service.ts @@ -0,0 +1,25 @@ +import {Injectable, TemplateRef} from '@angular/core'; +import {BehaviorSubject} from 'rxjs'; + +@Injectable({ +    providedIn: 'root' +}) +export class ModalService { + +    private modal = new BehaviorSubject<TemplateRef<any> | null>(null) + +    constructor() {} + +    showModal(template: TemplateRef<any>) { +        console.log("got here", template) +        this.modal.next(template) +    } + +    hideModal() { +        this.modal.next(null) +    } + +    getModalBehaviorSubject() { +        return this.modal; +    } +} diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 080c394..35d080d 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'; @@ -34,7 +34,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())) @@ -84,4 +86,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); +    } +  }  | 
