diff options
Diffstat (limited to 'ufund-ui/src/app/components/funding-basket/funding-basket.component.ts')
-rw-r--r-- | ufund-ui/src/app/components/funding-basket/funding-basket.component.ts | 29 |
1 files changed, 26 insertions, 3 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 920a7ef..45ca142 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 @@ -1,4 +1,4 @@ -import {Component, Input, OnInit, ViewChild} from '@angular/core'; +import {Component, Input, OnInit, TemplateRef, ViewChild} from '@angular/core'; import {UsersService} from '../../services/users.service'; import {Router} from '@angular/router'; import {CupboardService} from '../../services/cupboard.service'; @@ -7,6 +7,7 @@ import {AuthService} from '../../services/auth.service'; import {ToastsService, ToastType} from '../../services/toasts.service'; import {userType} from '../../models/User'; import {GoalType} from '../../models/Need'; +import {ModalService} from '../../services/modal.service'; @Component({ selector: 'app-funding-basket', @@ -17,16 +18,20 @@ import {GoalType} from '../../models/Need'; export class FundingBasketComponent implements OnInit { constructor( - private router: Router, protected cupboardService: CupboardService, protected usersService: UsersService, protected authService: AuthService, - private toastService: ToastsService + private toastService: ToastsService, + protected modalService: ModalService ) {} protected runningTotal = new BehaviorSubject(0) protected physicalTotal: string[] = [] + protected cancelModalFn?: () => void + protected acceptModalFn?: () => void + @ViewChild("contribution") contribution?: Input; + @ViewChild("overfundWarn") overfundWarn!: TemplateRef<any>; ngOnInit(): void { @@ -53,6 +58,24 @@ export class FundingBasketComponent implements OnInit { return; } + let overfundWarn = false + for (let item of order) { + let n = await firstValueFrom(this.cupboardService.getNeed(item.needID)) + if (n.current + item.quantity > n.maxGoal) { + overfundWarn = true + } + } + if (overfundWarn) { + this.modalService.showModal(this.overfundWarn) + let res = await new Promise((resovle, _) => { + this.cancelModalFn = () => resovle(false) + this.acceptModalFn = () => resovle(true) + }) + if (!res) { + return; + } + } + try { await firstValueFrom(this.cupboardService.checkoutNeed(order)) } catch (ex:any) { |