Skip to content

Commit

Permalink
Merge pull request #40 from Celesca/owen
Browse files Browse the repository at this point in the history
finish rating feature
  • Loading branch information
satanakorn authored Dec 5, 2024
2 parents 714cc77 + b813803 commit eda2063
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion frontend/src/profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const EditProfileModal = ({ isOpen, onClose, onSave, user }) => {
});
onSave(response.data);



Swal.fire({
title: "Good job!",
text: "Update Profile successful!",
Expand Down Expand Up @@ -605,7 +607,7 @@ const Profile = () => {
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
</svg>
))}
<span className="ml-2 text-gray-600">({(user.AverageRating || 0).toFixed(1)})</span>
<span className="ml-2 text-gray-600">Rating ({(user.AverageRating || 0).toFixed(1)})</span>
</div>

<div className="transform transition-all duration-300 hover:translate-x-2">
Expand Down
17 changes: 14 additions & 3 deletions src/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ export const userController = new Elysia({ prefix: "/user" })
}
)

// Get user details by userID
.get("/id/:UserID", async ({ params: { UserID }, error }) => {
// Get user details by userID
.get("/id/:UserID", async ({ params: { UserID }, error }) => {
const user = await prisma.user.findUnique({
where: { UserID: UserID },
select: {
Expand All @@ -130,16 +130,27 @@ export const userController = new Elysia({ prefix: "/user" })
Age: true,
Location: true,
AverageRating: true,
RatingsReceived: {
select: {
RatingValue: true,
},
},
},
});

if (!user) {
return error(404, "User not found");
}

return user;
// Calculate the average rating
const averageRating = user.RatingsReceived.length > 0
? user.RatingsReceived.reduce((sum, rating) => sum + rating.RatingValue, 0) / user.RatingsReceived.length
: 0;

return { ...user, AverageRating: averageRating };
})


// Get user details by userID with related skills and notifications
.get(
"/:userID",
Expand Down

0 comments on commit eda2063

Please sign in to comment.