diff options
Diffstat (limited to 'ufund-ui/src/app')
| -rw-r--r-- | ufund-ui/src/app/components/funding-basket/funding-basket.component.ts | 30 | ||||
| -rw-r--r-- | ufund-ui/src/app/services/cupboard.service.ts | 5 | 
2 files changed, 21 insertions, 14 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 18bb9b8..015d5b5 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 @@ -47,22 +47,28 @@ export class FundingBasketComponent implements OnInit {              order.push({id: +contribution.id, quantity: contribution.valueAsNumber});          } -        for (let c of document.querySelectorAll('.contribution')!) { -            let contribution = c as HTMLInputElement; -            try { -                let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id)); -                await firstValueFrom(this.cupboardService.checkoutNeed(need.id, +contribution.value)); -                need.current += +contribution.value; -                this.usersService.removeNeed(+need.id); -                this.toastService.sendToast(ToastType.INFO, "Checkout successful"); -            } catch (ex: any) { -                this.toastService.sendToast(ToastType.ERROR, ex.error); -            } +        try { +            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()      }      resetColor(ev: any) { -        console.log(ev); +        // console.log(ev);          (ev.target as HTMLInputElement).setAttribute("style", "border-color: unset")      }  } diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts index 9232c0c..786973e 100644 --- a/ufund-ui/src/app/services/cupboard.service.ts +++ b/ufund-ui/src/app/services/cupboard.service.ts @@ -47,7 +47,8 @@ export class CupboardService {          return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions())      } -    checkoutNeed(id: number, quantity: number) { -        return this.http.put(`${this.url}/checkout`, {needID: id, amount: quantity}, this.httpOptions()) +    checkoutNeed(data: {id: number, quantity: number}[]) { +        console.log("GOT HERE") +        return this.http.put(`${this.url}/checkout`, data, this.httpOptions())      }  }  | 
