diff options
author | benal01 <bja4245@rit.edu> | 2025-04-01 09:34:36 -0400 |
---|---|---|
committer | benal01 <bja4245@rit.edu> | 2025-04-01 09:34:36 -0400 |
commit | 7ed26c5ee7171a502f6f8527fc55de2bb77eab3b (patch) | |
tree | 2046e58c146097aac21c9e352771420c31df6589 /ufund-ui/src/app/components/need-edit/need-edit.component.ts | |
parent | ef46ddd082bb91d0262363536d46fe3eb4da47be (diff) | |
parent | d8330f1ac85b26d08ca4df5ce3875078d7b4f47f (diff) | |
download | JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.tar.gz JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.tar.bz2 JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.zip |
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b-jellysolutions
Diffstat (limited to 'ufund-ui/src/app/components/need-edit/need-edit.component.ts')
-rw-r--r-- | ufund-ui/src/app/components/need-edit/need-edit.component.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ufund-ui/src/app/components/need-edit/need-edit.component.ts b/ufund-ui/src/app/components/need-edit/need-edit.component.ts new file mode 100644 index 0000000..2462534 --- /dev/null +++ b/ufund-ui/src/app/components/need-edit/need-edit.component.ts @@ -0,0 +1,61 @@ +import { Component, Input, Output, EventEmitter } from '@angular/core'; +import { Need, GoalType } from '../../models/Need'; +import { CupboardService } from '../../services/cupboard.service'; +import { catchError, of } from 'rxjs'; +import { ToastsService, ToastType } from '../../services/toasts.service'; + +@Component({ + selector: 'app-need-edit', + standalone: false, + templateUrl: './need-edit.component.html', + styleUrl: './need-edit.component.css' +}) +export class NeedEditComponent { + constructor( + private cupboardService: CupboardService, + private toastService: ToastsService + + ) {} + + @Input() selectedNeed!: Need; + @Output() refreshNeedList = new EventEmitter<void>(); + + update(form: any) { + console.log(form); + const need: Need = { + name: form.name, + image: form.image, + location: form.location, + id: this.selectedNeed.id, //system will control this + maxGoal: form.maxGoal, + type: GoalType[form.type as keyof typeof GoalType], + urgent: form.urgent, + filterAttributes: [], + current: 0, + description: form.description + }; + + this.cupboardService.updateNeed(need.id, need) + .pipe(catchError((ex, _) => { + if (ex.status == 500) { + this.toastService.sendToast(ToastType.ERROR, 'Fields cannot be blank'); + } else if (ex.status == 400) { + this.toastService.sendToast(ToastType.ERROR, ex.error); + } else { + this.toastService.sendToast(ToastType.ERROR, "Error on creating need"); + } + return of() + })) + .subscribe( + (result) => { + if (result) { + console.log("need updated successfully"); + this.refreshNeedList.emit(); + } else { + console.log("need update failed"); + } + } + + ); + } +}
\ No newline at end of file |