Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish rating feature #40

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading