aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-03-26 15:38:46 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-03-26 15:38:46 -0400
commitea13cf6ab3b71ff5e83fca876ec71fec1f7b00ae (patch)
tree4450553037eaec406d8e0bb2c3a4200b188f01ea /ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
parent5f03e80712f7a18370b5118fde5327bde1b6fbbf (diff)
downloadJellySolutions-ea13cf6ab3b71ff5e83fca876ec71fec1f7b00ae.tar.gz
JellySolutions-ea13cf6ab3b71ff5e83fca876ec71fec1f7b00ae.tar.bz2
JellySolutions-ea13cf6ab3b71ff5e83fca876ec71fec1f7b00ae.zip
Make frontend work with the new backend checkout system
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.ts122
1 files changed, 60 insertions, 62 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 e654711..faa7e0b 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,11 +1,9 @@
import {Component, Input, OnInit, ViewChild} from '@angular/core';
-import {User} from '../../models/User';
-import { UsersService } from '../../services/users.service';
-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, catchError, firstValueFrom, Observable } from 'rxjs';
+import {UsersService} from '../../services/users.service';
+import {Router} from '@angular/router';
+import {CupboardService} from '../../services/cupboard.service';
+import {catchError, firstValueFrom, Observable} from 'rxjs';
+import {AuthService} from '../../services/auth.service';
@Component({
selector: 'app-funding-basket',
@@ -14,67 +12,67 @@ import { BehaviorSubject, catchError, firstValueFrom, Observable } from 'rxjs';
styleUrl: './funding-basket.component.css'
})
export class FundingBasketComponent implements OnInit {
- statusText: any;
+ statusText: any;
- constructor(
- private router: Router,
- protected cupboardService: CupboardService,
- protected usersService: UsersService
- ) {}
+ constructor(
+ private router: Router,
+ protected cupboardService: CupboardService,
+ protected usersService: UsersService,
+ private authService: AuthService
+ ) {}
- @ViewChild("contribution") contribution?: Input;
- @Input() isValid: boolean = true;
+ @ViewChild("contribution") contribution?: Input;
+ @Input() isValid: boolean = true;
- // this is for login rerouting
- ngOnInit(): void {
- if (!this.usersService.getCurrentUser()) {
- this.router.navigate(['/login'], {queryParams: {redir: this.router.url}});
- return;
- }
-
- this.usersService.refreshBasket();
- // this.usersService.removeNeed(); <- call this to remove
- }
+ // this is for login rerouting
+ ngOnInit(): void {
+ if (!this.authService.getCurrentUser()) {
+ this.router.navigate(['/login'], {queryParams: {redir: this.router.url}});
+ return;
+ }
- async checkout() {
- this.isValid = true;
- for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) {
- let contribution = c as HTMLInputElement;
- contribution.setAttribute("style","");
- if ( contribution.value == '' || contribution.valueAsNumber <= 0) {
- this.isValid = false;
- contribution.setAttribute("style","color: #ff0000");
- }
+ this.usersService.refreshBasket();
+ // this.usersService.removeNeed(); <- call this to remove
}
- if (this.isValid) {
- for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) {
- let contribution = c as HTMLInputElement;
- let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id));
- need.current +=+ contribution.value;
- this.usersService.removeNeed(+need.id);
- this.cupboardService.updateNeed(need.id, need)
- .pipe(catchError((ex, r) => {
- 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');
- }
- });
- }
- }
- }
+ async checkout() {
+ this.isValid = true;
+ for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) {
+ let contribution = c as HTMLInputElement;
+ contribution.setAttribute("style", "");
+ if (contribution.value == '' || contribution.valueAsNumber <= 0) {
+ this.isValid = false;
+ contribution.setAttribute("style", "color: #ff0000");
+ }
+ }
+ if (this.isValid) {
+ for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) {
+ let contribution = c as HTMLInputElement;
+ let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id));
+ need.current += +contribution.value;
+ this.usersService.removeNeed(+need.id);
+ this.cupboardService.checkoutNeed(need.id, +contribution.value)
+ .pipe(catchError((ex, _) => {
+ 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');
+ }
+ });
+ }
+ }
+ }
}