diff --git a/src/components/UserProfileComponents/Rating.vue b/src/components/UserProfileComponents/Rating.vue index 8aff6bad071841e4f6baf1c2825ca748b46c095f..1db98bfb010248d1cf3d554df1f946a6867e6dc9 100644 --- a/src/components/UserProfileComponents/Rating.vue +++ b/src/components/UserProfileComponents/Rating.vue @@ -31,7 +31,7 @@ </li> <li> <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> - Rating ikke tilgjengelig + Ingen vurderinger </p> </li> </ul> @@ -47,7 +47,7 @@ export default { methods: { getFill(i) { if (i <= this.rating) { - return "w-5 h-5 text-warn"; + return "w-5 h-5 text-warn-medium"; } return "w-5 h-5 text-gray-300 dark:text-gray-500"; }, diff --git a/src/components/UserProfileComponents/UserProfile.vue b/src/components/UserProfileComponents/UserProfile.vue index 9a877d2401a653468dfd56a6ccccb2afac735922..5e8bf9958539dc0f29064089d7bcc90e59496c37 100644 --- a/src/components/UserProfileComponents/UserProfile.vue +++ b/src/components/UserProfileComponents/UserProfile.vue @@ -88,7 +88,7 @@ {{ user.firstName }} {{ user.lastName }} </h5> <div> - <rating-component :rating="renterRating" :ratingType="'Leietaker'" /> + <rating-component :rating="renterRating" :ratingType="'Leietaker'"/> <rating-component :rating="ownerRating" :ratingType="'Utleier'" /> </div> @@ -106,7 +106,8 @@ <script> import RatingComponent from "@/components/UserProfileComponents/Rating.vue"; import { parseCurrentUser } from "@/utils/token-utils"; -import { getUser, getAverageRating } from "@/utils/apiutil"; +import { getUser} from "@/utils/apiutil"; +import UserService from "@/services/user.service" export default { name: "LargeProfileCard", @@ -135,10 +136,14 @@ export default { return; } this.user = await getUser(this.id); - let rating = await getAverageRating(this.id); - if (rating >= 0 && rating <= 5) { - this.renterRating = rating; - this.ownerRating = rating; + let ratingAsOwner = await UserService.getUserRatingAsOwner(this.id); + let ratingAsRenter = await UserService.getUserRatingAsRenter(this.id) + + if (ratingAsOwner >= 0 && ratingAsOwner <= 5) { + this.ownerRating = ratingAsOwner; + } + if (ratingAsRenter >= 0 && ratingAsRenter <= 5){ + this.renterRating = ratingAsRenter; } }, getProfilePicture() { diff --git a/src/services/user.service.js b/src/services/user.service.js index f07ef8c3acda54f54fa1189b63cbb07aa0412c87..909e34d6374f44ec32ac441a1df25c85754f7ede 100644 --- a/src/services/user.service.js +++ b/src/services/user.service.js @@ -5,33 +5,51 @@ import axios from "axios"; const API_URL = process.env.VUE_APP_BASEURL; class UserService { - async getUserFromId(userId) { - return await axios - .get(API_URL + "users/" + userId + "/profile", { - headers: tokenHeader(), - }) - .then((res) => { - return res.data; - }) - .catch((err) => console.error(err)); - } + async getUserFromId(userId) { + return await axios + .get(API_URL + "users/" + userId + "/profile", { + headers: tokenHeader(), + }) + .then((res) => { + return res.data; + }) + .catch((err) => console.error(err)); + } - async getUserRatingAverage(userId) { - return await axios - .get(API_URL + "rating/" + userId + "/average", { - headers: tokenHeader(), - }) - .then((res) => { - return res.data; - }) - .catch((err) => console.error(err)); - } + async getUserRatingAverage(userId) { + return await axios + .get(API_URL + "rating/" + userId + "/average", { + headers: tokenHeader(), + }) + .then((res) => { + return res.data; + }) + .catch((err) => console.error(err)); + } - //TODO - async getUserRatingAsOwner() {} + async getUserRatingAsOwner(userId) { + return await axios + .get(API_URL + "rating/" + userId + "/average/owner", { + headers: tokenHeader(), + }) + .then((res) => { + return res.data; + }) + .catch((err) => console.error(err)) + } - //TODO - async getUserRatingAsRenter() {} + async getUserRatingAsRenter(userId) { + return await axios + .get(API_URL + "rating/" + userId + "/average/renter", { + headers: tokenHeader(), + }) + .then((res) => { + return res.data; + }) + .catch((err) => console.error(err)) + } } - -export default new UserService(); + export + default + new + UserService(); \ No newline at end of file