From ab35efb06b926e8a3aee5cfc8d1fa908aa4a4707 Mon Sep 17 00:00:00 2001 From: sowgro Date: Wed, 26 Mar 2025 18:14:47 -0400 Subject: Fix cupboard access checking and logging --- .../components/need-page/need-page.component.ts | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'ufund-ui/src/app/components/need-page/need-page.component.ts') 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 597d0e0..e38554c 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 @@ -2,30 +2,30 @@ import {Component, Input} from '@angular/core'; import {GoalType, Need} from '../../models/Need'; import {ActivatedRoute} from "@angular/router"; import {CupboardService} from "../../services/cupboard.service"; -import { NgFor } from '@angular/common'; +import {NgFor} from '@angular/common'; @Component({ - selector: 'app-need-page', - standalone: false, - templateUrl: './need-page.component.html', - styleUrl: './need-page.component.css' + selector: 'app-need-page', + standalone: false, + templateUrl: './need-page.component.html', + styleUrl: './need-page.component.css' }) export class NeedPageComponent { - constructor( - private route: ActivatedRoute, - private cupboardService: CupboardService, - ) {} + constructor( + private route: ActivatedRoute, + private cupboardService: CupboardService, + ) {} - public GoalType = GoalType; + public GoalType = GoalType; - @Input() need?: Need; + @Input() need?: Need; - ngOnInit(): void { - const id = Number(this.route.snapshot.paramMap.get('id')); - this.cupboardService.getNeed(id).subscribe(n => this.need = n); - } + ngOnInit(): void { + const id = Number(this.route.snapshot.paramMap.get('id')); + this.cupboardService.getNeed(id).subscribe(n => this.need = n); + } - back() { - window.history.back(); - } -} \ No newline at end of file + back() { + window.history.back(); + } +} -- cgit v1.2.3 From 896e1219526a19400c7143b274193f8b818d6156 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 31 Mar 2025 23:37:00 -0400 Subject: Commit half working changes to move to my laptop --- .../components/need-page/need-page.component.ts | 62 ++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) (limited to 'ufund-ui/src/app/components/need-page/need-page.component.ts') 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) { + + } } -- cgit v1.2.3