diff --git a/frontend/src/profile.jsx b/frontend/src/profile.jsx index 5249ff8..e1b7708 100644 --- a/frontend/src/profile.jsx +++ b/frontend/src/profile.jsx @@ -44,6 +44,8 @@ const EditProfileModal = ({ isOpen, onClose, onSave, user }) => { }); onSave(response.data); + + Swal.fire({ title: "Good job!", text: "Update Profile successful!", @@ -605,7 +607,7 @@ const Profile = () => { ))} - ({(user.AverageRating || 0).toFixed(1)}) + Rating ({(user.AverageRating || 0).toFixed(1)})
diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index 39a795e..fb6ff98 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -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: { @@ -130,6 +130,11 @@ export const userController = new Elysia({ prefix: "/user" }) Age: true, Location: true, AverageRating: true, + RatingsReceived: { + select: { + RatingValue: true, + }, + }, }, }); @@ -137,9 +142,15 @@ export const userController = new Elysia({ prefix: "/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",