diff options
| author | Akash Keshav <112591754+domesticchores@users.noreply.github.com> | 2025-03-18 15:59:16 -0400 | 
|---|---|---|
| committer | Akash Keshav <112591754+domesticchores@users.noreply.github.com> | 2025-03-18 15:59:16 -0400 | 
| commit | 9d90b2a29b1f47b6271fd9ea87989a4195cf5ee6 (patch) | |
| tree | ff1bef34d79c4b7e4b514bbacd3ac5f91c21d117 /ufund-ui/src | |
| parent | cd9dfcec9e7ae9fe6f08b61927b16cf76b8bcef7 (diff) | |
| download | JellySolutions-9d90b2a29b1f47b6271fd9ea87989a4195cf5ee6.tar.gz JellySolutions-9d90b2a29b1f47b6271fd9ea87989a4195cf5ee6.tar.bz2 JellySolutions-9d90b2a29b1f47b6271fd9ea87989a4195cf5ee6.zip  | |
working update need; broken remove basket. -ak
Diffstat (limited to '')
| -rw-r--r-- | ufund-ui/src/app/components/funding-basket/funding-basket.component.html | 1 | ||||
| -rw-r--r-- | ufund-ui/src/app/components/funding-basket/funding-basket.component.ts | 35 | 
2 files changed, 30 insertions, 6 deletions
diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html index 178a2cd..30c3167 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html @@ -35,4 +35,5 @@  <div>      <p *ngIf="!isValid">Invalid input in funding basket!</p>      <button type="submit" class="checkout" title="checkout" (click)="checkout()">Checkout</button> +    <span *ngIf="statusText">{{statusText | async}}</span>  </div>
\ No newline at end of file diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts index a7a38b8..7f086ec 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts @@ -5,7 +5,7 @@ import { Need } from '../../models/Need';  import { NeedListComponent } from '../need-list/need-list.component';  import { Router } from '@angular/router';  import { CupboardService } from '../../services/cupboard.service'; -import { BehaviorSubject, firstValueFrom } from 'rxjs'; +import { BehaviorSubject, catchError, firstValueFrom, Observable } from 'rxjs';  @Component({      selector: 'app-funding-basket', @@ -14,6 +14,7 @@ import { BehaviorSubject, firstValueFrom } from 'rxjs';      styleUrl: './funding-basket.component.css'  })  export class FundingBasketComponent implements OnInit { +  statusText: any;    constructor(      private router: Router, @@ -38,7 +39,7 @@ export class FundingBasketComponent implements OnInit {    async checkout() {      this.isValid = true;      for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { -      var contribution = c as HTMLInputElement; +      let contribution = c as HTMLInputElement;        console.log(contribution.value, contribution.id);        contribution.setAttribute("style","");        if ( contribution.value == '' || contribution.valueAsNumber < 0) { @@ -48,12 +49,34 @@ export class FundingBasketComponent implements OnInit {      }      if (this.isValid) {        for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { -        var contribution = c as HTMLInputElement; -        var need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id)); +        let contribution = c as HTMLInputElement; +        let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id));          need.current +=+ contribution.value;          console.log(need); -        this.cupboardService.updateNeed(+contribution.id, need); -        this.usersService.removeNeed(+contribution.id); +        this.usersService.removeNeed(need.id); +        this.cupboardService.updateNeed(need.id, need) +                    .pipe(catchError((ex, r) => { +                        console.log(ex.status); +                        if (ex.status == 500) { +                            this.statusText.next("Fields cannot be blank"); +                        } else if (ex.status == 400) { +                            this.statusText.next("Goal must be greater than 0"); +                        } else { +                            this.statusText.next("Error on creating need"); +                        } +                        return new Observable<string>(); +                    })) +                    .subscribe( +                        (result) => { +                            if (result) { +                                console.log("need updated successfully"); +                                //this.needList?.refresh() +                            } else { +                                console.log("need update failed"); +                            } +                        } +         +                    );        }      }    }  | 
