diff --git a/src/components/UserProfileComponents/UserProfile.vue b/src/components/UserProfileComponents/UserProfile.vue index c2d2a05e395e40893ab49a5693e028dbec97e1e1..186f986c9513f9ed8d0cc44f36e23c4572ef4581 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 1639127d4706c607415316a00f95829f00e3eef5..5aeb0201f8a3c32d04b6eae18808d0ec2f763fb3 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, {