diff options
author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-04-01 07:47:16 -0400 |
---|---|---|
committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-04-01 07:47:16 -0400 |
commit | d8330f1ac85b26d08ca4df5ce3875078d7b4f47f (patch) | |
tree | 2046e58c146097aac21c9e352771420c31df6589 /ufund-ui/src/app/components/need-page/need-page.component.ts | |
parent | bc9d3417795d841b4cb3e9fb022f8d61448af946 (diff) | |
parent | 233fe120d2a9b30e0150401ebdfeb946dc9c2c07 (diff) | |
download | JellySolutions-d8330f1ac85b26d08ca4df5ce3875078d7b4f47f.tar.gz JellySolutions-d8330f1ac85b26d08ca4df5ce3875078d7b4f47f.tar.bz2 JellySolutions-d8330f1ac85b26d08ca4df5ce3875078d7b4f47f.zip |
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b
Diffstat (limited to 'ufund-ui/src/app/components/need-page/need-page.component.ts')
-rw-r--r-- | ufund-ui/src/app/components/need-page/need-page.component.ts | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/ufund-ui/src/app/components/need-page/need-page.component.ts b/ufund-ui/src/app/components/need-page/need-page.component.ts index e38554c..ad4cacf 100644 --- a/ufund-ui/src/app/components/need-page/need-page.component.ts +++ b/ufund-ui/src/app/components/need-page/need-page.component.ts @@ -1,8 +1,12 @@ import {Component, Input} from '@angular/core'; import {GoalType, Need} from '../../models/Need'; -import {ActivatedRoute} from "@angular/router"; +import {ActivatedRoute, Router} from "@angular/router"; import {CupboardService} from "../../services/cupboard.service"; -import {NgFor} from '@angular/common'; +import {userType} from '../../models/User'; +import {AuthService} from '../../services/auth.service'; +import {catchError, of} from 'rxjs'; +import {ToastsService, ToastType} from '../../services/toasts.service'; +import {UsersService} from '../../services/users.service'; @Component({ selector: 'app-need-page', @@ -14,11 +18,15 @@ export class NeedPageComponent { constructor( private route: ActivatedRoute, private cupboardService: CupboardService, + private authService: AuthService, + private usersService: UsersService, + private toastService: ToastsService, + private router: Router ) {} public GoalType = GoalType; - @Input() need?: Need; + @Input() need!: Need; ngOnInit(): void { const id = Number(this.route.snapshot.paramMap.get('id')); @@ -28,4 +36,52 @@ export class NeedPageComponent { back() { window.history.back(); } + + isManager() { + const type = this.authService.getCurrentUser()?.type; + return type === ("MANAGER" as unknown as userType); + } + + isHelper() { + const type = this.authService.getCurrentUser()?.type; + return type === ("HELPER" as unknown as userType); + } + + add(need: Need) { + 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) + .pipe(catchError((err, _) => { + console.error(err); + return of(); + })) + .subscribe(() => { + this.usersService.refreshBasket(); + }); + } else { + this.toastService.sendToast(ToastType.ERROR, "This need is already in your basket!") + } + } + } + + delete(id : number) { + this.cupboardService.deleteNeed(id) + .pipe(catchError((ex, r) => { + this.toastService.sendToast(ToastType.ERROR, ex.error) + return of() + })) + .subscribe(() => { + // this.needs = this.needs.filter(n => n.id !== id) + this.toastService.sendToast(ToastType.INFO, "Need deleted") + this.router.navigate(['/']) + }) + // this.refresh(); + } + + edit(need: Need) { + + } } |