From e3f327aeaa2afe4c6b1a241cbf4cf41d036d178b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20R=C3=B8skaft?= <haakoero@stud.ntnu.no> Date: Fri, 6 May 2022 15:48:15 +0200 Subject: [PATCH] Fixed so rating now displayes properly on user profile --- .../UserProfileComponents/UserProfile.vue | 14 ++++++------ src/services/user.service.js | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/components/UserProfileComponents/UserProfile.vue b/src/components/UserProfileComponents/UserProfile.vue index c2d2a05..186f986 100644 --- a/src/components/UserProfileComponents/UserProfile.vue +++ b/src/components/UserProfileComponents/UserProfile.vue @@ -95,7 +95,7 @@ </h5> <div> <rating-component :rating="renterRating" :ratingType="'Leietaker'" /> - <rating-component :rating="ownerRating" :ratingType="'Utleier'" /> + <RatingComponent :rating="ownerRating" :ratingType="'Utleier'"></RatingComponent> </div> <div @@ -161,11 +161,11 @@ export default { this.isCurrentUser = true; this.user = this.currentUser; this.user = await UserService.getUserFromId(this.user.accountId); - return; + } else { + this.user = await getUser(this.id); } - this.user = await getUser(this.id); - let ratingAsOwner = await UserService.getUserRatingAsOwner(this.id); - let ratingAsRenter = await UserService.getUserRatingAsRenter(this.id); + let ratingAsOwner = await UserService.getUserRatingAverageOwner(this.id); + let ratingAsRenter = await UserService.getUserRatingAverageRenter(this.id); if (ratingAsOwner >= 0 && ratingAsOwner <= 5) { this.ownerRating = ratingAsOwner; @@ -186,8 +186,8 @@ export default { this.logout(); }, }, - beforeMount() { - this.getUser(); + async beforeMount() { + await this.getUser(); }, }; </script> diff --git a/src/services/user.service.js b/src/services/user.service.js index 1639127..5aeb020 100644 --- a/src/services/user.service.js +++ b/src/services/user.service.js @@ -39,6 +39,28 @@ class UserService { .catch((err) => console.error(err)); } + async getUserRatingAverageOwner(userId) { + return await axios + .get(API_URL + "rating/" + userId + "/average/owner", { + headers: tokenHeader(), + }) + .then((res) => { + return res.data; + }) + .catch((err) => console.error(err)); + } + + async getUserRatingAverageRenter(userId) { + return await axios + .get(API_URL + "rating/" + userId + "/average/renter", { + headers: tokenHeader(), + }) + .then((res) => { + return res.data; + }) + .catch((err) => console.error(err)); + } + async setListingToDeleted(listingId) { return await axios .delete(API_URL + "listing/" + listingId, { -- GitLab