diff options
Diffstat (limited to 'ufund-ui/src/app/components/funding-basket')
| -rw-r--r-- | ufund-ui/src/app/components/funding-basket/funding-basket.component.ts | 23 | 
1 files changed, 6 insertions, 17 deletions
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 015d5b5..5d94124 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 @@ -2,7 +2,7 @@ import {Component, Input, OnInit, ViewChild} from '@angular/core';  import {UsersService} from '../../services/users.service';  import {Router} from '@angular/router';  import {CupboardService} from '../../services/cupboard.service'; -import {catchError, firstValueFrom, Observable} from 'rxjs'; +import {firstValueFrom} from 'rxjs';  import {AuthService} from '../../services/auth.service';  import {ToastsService, ToastType} from '../../services/toasts.service'; @@ -32,11 +32,10 @@ export class FundingBasketComponent implements OnInit {          }          this.usersService.refreshBasket(); -        // this.usersService.removeNeed(); <- call this to remove      }      async checkout() { -        let order: { id: number, quantity: number }[] = [] +        let order: { needID: number, quantity: number }[] = []          for (let contribution of document.querySelectorAll<HTMLInputElement>('.contribution')!) {              if (contribution.value == '' || contribution.valueAsNumber <= 0) { @@ -44,31 +43,21 @@ export class FundingBasketComponent implements OnInit {                  this.toastService.sendToast(ToastType.ERROR, "Invalid input in funding basket!")                  return;              } -            order.push({id: +contribution.id, quantity: contribution.valueAsNumber}); +            order.push({needID: +contribution.id, quantity: contribution.valueAsNumber});          }          try { -            this.cupboardService.checkoutNeed(order) +            await firstValueFrom(this.cupboardService.checkoutNeed(order))          } catch (ex:any) {              this.toastService.sendToast(ToastType.ERROR, ex.error);              return          } -        console.log(order) - -        for (let contribution of order) { -            let need = await firstValueFrom(this.cupboardService.getNeed(contribution.id)) -            need.current += contribution.quantity; -            this.usersService.removeNeed(need.id); -            this.toastService.sendToast(ToastType.INFO, "Checkout successful"); -        } - -        // this.usersService.getBasket().subscribe(console.log) -        // this.usersService.refreshBasket() +        order.forEach(contribution => this.usersService.removeNeed(contribution.needID)) +        this.toastService.sendToast(ToastType.INFO, "Checkout successful");      }      resetColor(ev: any) { -        // console.log(ev);          (ev.target as HTMLInputElement).setAttribute("style", "border-color: unset")      }  }  | 
