aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/need-list/need-list.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-ui/src/app/components/need-list/need-list.component.ts')
-rw-r--r--ufund-ui/src/app/components/need-list/need-list.component.ts25
1 files changed, 14 insertions, 11 deletions
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts
index e1c0de1..25f05d6 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.ts
+++ b/ufund-ui/src/app/components/need-list/need-list.component.ts
@@ -105,19 +105,22 @@ export class NeedListComponent {
return type === ("HELPER" as unknown as userType);
}
- add(need: number) {
+ add(need: Need) {
const currentUser = this.usersService.getCurrentUser();
+ //console.log("get current user in angular:", currentUser)
if (currentUser) {
- this.usersService.updateUser(currentUser.username, currentUser).subscribe(() => {
- const currentUser = this.usersService.getCurrentUser();
- if (currentUser && currentUser.basket) {
- currentUser.basket.push(need);
- console.log("added to basket");
- }
- error: (err: any) => {
- console.error(err);
- }
- });
+ if (!currentUser.basket.includes(need.id)) {
+ currentUser.basket.push(need.id);
+ this.usersService.updateUser(currentUser).subscribe(() => {
+ this.usersService.refreshBasket();
+ error: (err: any) => {
+ console.error(err);
+ }
+ });
+ } else {
+ window.alert("This need is already in your basket!")
+ }
+
}