From 7d756eb00fe5d1ce5080182d83b2c8a9bad465aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anders=20H=C3=B8vik?= <andehovi@stud.ntnu.no>
Date: Thu, 2 May 2024 17:02:09 +0200
Subject: [PATCH] Change array-type of goals

---
 .../UserProfile/ExternalProfile.vue           | 26 +++++++++++--------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/components/UserProfile/ExternalProfile.vue b/src/components/UserProfile/ExternalProfile.vue
index a602a02..efca448 100644
--- a/src/components/UserProfile/ExternalProfile.vue
+++ b/src/components/UserProfile/ExternalProfile.vue
@@ -1,8 +1,8 @@
 <script setup lang="ts">
 import {useRoute, useRouter} from "vue-router";
 
-import {onMounted, ref} from "vue";
-import {UserService, type ProfileDTO, GoalService} from "@/api";
+import {onMounted, type Ref, ref, type UnwrapRef} from "vue";
+import {UserService, type ProfileDTO, GoalService, type GoalDTO} from "@/api";
 
 let numberOfHistory = 6;
 
@@ -12,7 +12,7 @@ let cardTitles = ["Spain tour", "Food waste", "Coffee", "Concert", "New book", "
 let hasHistory = ref(true)
 let firstname = ref();
 let lastname = ref();
-let goals = ref([]);
+let goals: Ref<UnwrapRef<GoalDTO[]>> = ref([]);
 
 let username = ref()
 
@@ -41,7 +41,7 @@ function toRoadmap(){
 //todo Make a store of a friend-instance
 onMounted(async () => {
   try {
-    goals = await UserService.getProfile({
+    let response = await UserService.getProfile({
       userId: id.value.id
     })
     profile = response;
@@ -62,13 +62,17 @@ function addFriend() {
 
 }
 async function getGoals() {
-  let response = await GoalService.getGoals();
-  console.log("number of goals: ", response.length )
-  if(response.length > 0) {
-    hasHistory.value = true
-  }else{
-    hasHistory.value = false
-    console.log('No history')
+  try {
+    goals.value = await GoalService.getGoals();
+    console.log("number of goals: ", goals.value.length)
+    if (goals.value.length > 0) {
+      hasHistory.value = true
+    } else {
+      hasHistory.value = false
+      console.log('No history')
+    }
+  }catch (error){
+    console.error("Something went wrong getting the goals: " , error)
   }
 }
 
-- 
GitLab