diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2025-04-06 15:15:47 -0400 | 
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2025-04-06 15:15:47 -0400 | 
| commit | 9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6 (patch) | |
| tree | 8af111a538a8d6361e1cf07467b9c31568284921 /ufund-ui/src/app/services | |
| parent | 1ac878b4aaa19ab889c7a98b7dab6acd57c778b3 (diff) | |
| parent | 04cb51b2e7891785c956c5faa73fb88cc04e82e0 (diff) | |
| download | JellySolutions-9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6.tar.gz JellySolutions-9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6.tar.bz2 JellySolutions-9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6.zip  | |
Merge branch 'main' into light-mode
# Conflicts:
#	ufund-ui/src/app/app.component.html
#	ufund-ui/src/app/components/funding-basket/funding-basket.component.html
#	ufund-ui/src/app/components/need-list/need-list.component.html
#	ufund-ui/src/app/components/need-page/need-page.component.css
Diffstat (limited to '')
| -rw-r--r-- | ufund-ui/src/app/services/cupboard.service.ts | 8 | ||||
| -rw-r--r-- | ufund-ui/src/app/services/modal.service.ts | 25 | ||||
| -rw-r--r-- | ufund-ui/src/app/services/users.service.ts | 35 | 
3 files changed, 61 insertions, 7 deletions
diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts index 9232c0c..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[]> { @@ -47,7 +47,7 @@ export class CupboardService {          return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions())      } -    checkoutNeed(id: number, quantity: number) { -        return this.http.put(`${this.url}/checkout`, {needID: id, amount: quantity}, this.httpOptions()) +    checkoutNeed(data: {needID: number, quantity: number}[]) { +        return this.http.put(`${this.url}/checkout`, data, this.httpOptions())      }  } 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 4080ebf..688d6e4 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'; @@ -21,11 +21,22 @@ export class UsersService {          })      }); +    httpOptions2 = () => ({ +        headers: new HttpHeaders({ +            'Content-Type': 'application/json', +            "jelly-api-key": this.authService.getApiKey() +        }), +        responseType: "text" as "json" // don't ask me how or why this works, bc i have no clue... +        // see the relevant angular bug report https://github.com/angular/angular/issues/18586 +    }); +      constructor(          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())) @@ -35,6 +46,10 @@ export class UsersService {          return this.http.get<User>(`${this.url}/${id}`, this.httpOptions())      } +    getCount(): Observable<number> { +        return this.http.get<number>(`${this.url}/count`, this.httpOptions2()) +    } +      updateUser(user: User): Observable<User> {          console.log(`${this.url}/${user.username}`, user, this.httpOptions)          return this.http.put<User>(`${this.url}/${user.username}`, user, this.httpOptions()) @@ -45,7 +60,9 @@ export class UsersService {      }      refreshBasket() { -        let promiseArr = this.authService.getCurrentUser()!.basket.map(async needID => { +        let usr = this.authService.getCurrentUser(); +        if (!usr) return; +        let promiseArr = usr.basket.map(async needID => {              return await firstValueFrom(this.cupboardService.getNeed(needID));          })          Promise.all(promiseArr).then(r => this.basket.next(r)); @@ -71,4 +88,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); +    } +  }  | 
