From 549e62239f82b0f40d94c70b9023a7f7825818da Mon Sep 17 00:00:00 2001 From: Owen <91054189+satanakorn@users.noreply.github.com> Date: Wed, 27 Nov 2024 22:47:34 +0700 Subject: [PATCH 1/2] update rating --- frontend/src/Rating.jsx | 49 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/frontend/src/Rating.jsx b/frontend/src/Rating.jsx index 7f9576e..f04b879 100644 --- a/frontend/src/Rating.jsx +++ b/frontend/src/Rating.jsx @@ -102,35 +102,34 @@ const Rating = () => { console.log(UserID) console.log(ratedUserID) - console.log(RatingValue) + console.log(typeof RatingValue); console.log(Comment) // Add rating - // Add rating - await Axios.post(`http://localhost:3000/rating/rateuser`, { - ratedByID: UserID, - ratedUserID: ratedUserID, - ratingValue: RatingValue, - comment: Comment, - }, - { - headers: { - Authorization: `Bearer ${localStorage.getItem('token')}`, - }, - } - ); - - // Reset form - setSelectedTeam(''); - setSelectedUser(''); - setRatingValue(''); - setComment(''); - setErrorMessage(''); - alert('บันทึกคะแนนสำเร็จ'); - } catch (error) { - console.error('Error:', error); - setErrorMessage('เกิดข้อผิดพลาดในการบันทึกข้อมูล'); + await Axios.post(`http://localhost:3000/rating/rateuser`, { + ratedByID: UserID, + ratedUserID: ratedUserID, + ratingValue: parseInt(RatingValue), + comment: Comment, + }, + { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}`, + }, } + ); + + // Reset form + setSelectedTeam(''); + setSelectedUser(''); + setRatingValue(''); + setComment(''); + setErrorMessage(''); + alert('บันทึกคะแนนสำเร็จ'); + } catch (error) { + console.error('Error:', error); + setErrorMessage('เกิดข้อผิดพลาดในการบันทึกข้อมูล'); + } }; return ( From a5ec4f0e64d2cf289e1ff1d7f2a7878b2adb0b46 Mon Sep 17 00:00:00 2001 From: Owen <91054189+satanakorn@users.noreply.github.com> Date: Wed, 27 Nov 2024 22:54:42 +0700 Subject: [PATCH 2/2] update rating --- src/controllers/teamController.ts | 189 ++++++++++++++++++------------ 1 file changed, 115 insertions(+), 74 deletions(-) diff --git a/src/controllers/teamController.ts b/src/controllers/teamController.ts index 615bd84..913897b 100644 --- a/src/controllers/teamController.ts +++ b/src/controllers/teamController.ts @@ -8,91 +8,45 @@ export const teamController = new Elysia({ prefix: "/team" }) return teams; }) -// Get users in a team -.get("/users/:teamID", async ({ params: { teamID }, error }) => { - const users = await prisma.userTeam.findMany({ - where: { - TeamID: parseInt(teamID, 10), - }, - include: { - User: true, - }, - }); - if (!users || users.length === 0) { - return error(404, "Users not found"); - } - return users.map(userTeam => userTeam.User); -}, { - params: t.Object({ - teamID: t.String(), - }), -}) -// Get Team by TeamID -.get("/getTeam", async ({ query: { TeamID }, error }) => { - const team = await prisma.team.findFirst({ - where: { - TeamID: TeamID, - }, - }); - if (!team) { - return error(404, "Team not found"); - } + + + + + + + + + + + + + + + + + + + + + + + + + + + - return team; -}, { - query: t.Object({ - TeamID: t.Number(), - }), -}) -// Check if a user is part of a team -.get("/checkteam", async ({ query: { TeamID, UserID }, error }) => { - if (!TeamID || !UserID) { - return error(400, "TeamID and UserID are required"); - } - const teamMember = await prisma.userTeam.findFirst({ - where: { - TeamID: TeamID, - UserID: UserID, - }, - }); - if (!teamMember) { - return error(404, "User is not part of the team"); - } - return { valid: true }; -}, { - query: t.Object({ - TeamID: t.Number(), - UserID: t.String(), - }), -}) -// Other endpoints... -// Get TeamID from TeamName -.get("/getTeamID", async ({ query: { TeamName }, error }) => { - const team = await prisma.team.findFirst({ - where: { - TeamName: TeamName, - }, - }); - if (!team) { - return error(404, "Team not found"); - } - return {TeamID: team.TeamID}; - }, { - query: t.Object({ - TeamName: t.String(), - }), - }) .get("/finduserteam/:teamID", async ({ params, error }) => { const teamID = parseInt(params.teamID, 10); // Ensure teamID is a number if (isNaN(teamID)) { @@ -306,4 +260,91 @@ export const teamController = new Elysia({ prefix: "/team" }) teamID: t.Number(), userID: t.String(), }), -}) \ No newline at end of file +}) + + +// Get users in a team +.get("/users/:teamID", async ({ params: { teamID }, error }) => { + const users = await prisma.userTeam.findMany({ + where: { + TeamID: parseInt(teamID, 10), + }, + include: { + User: true, + }, + }); + + if (!users || users.length === 0) { + return error(404, "Users not found"); + } + + return users.map(userTeam => userTeam.User); +}, { + params: t.Object({ + teamID: t.String(), + }), +}) + +// Get Team by TeamID +.get("/getTeam", async ({ query: { TeamID }, error }) => { + const team = await prisma.team.findFirst({ + where: { + TeamID: TeamID, + }, + }); + + if (!team) { + return error(404, "Team not found"); + } + + return team; +}, { + query: t.Object({ + TeamID: t.Number(), + }), +}) + +// Check if a user is part of a team +.get("/checkteam", async ({ query: { TeamID, UserID }, error }) => { + if (!TeamID || !UserID) { + return error(400, "TeamID and UserID are required"); + } + + const teamMember = await prisma.userTeam.findFirst({ + where: { + TeamID: TeamID, + UserID: UserID, + }, + }); + + if (!teamMember) { + return error(404, "User is not part of the team"); + } + + return { valid: true }; +}, { + query: t.Object({ + TeamID: t.Number(), + UserID: t.String(), + }), +}) + +// Other endpoints... +// Get TeamID from TeamName +.get("/getTeamID", async ({ query: { TeamName }, error }) => { + const team = await prisma.team.findFirst({ + where: { + TeamName: TeamName, + }, + }); + + if (!team) { + return error(404, "Team not found"); + } + + return {TeamID: team.TeamID}; + }, { + query: t.Object({ + TeamName: t.String(), + }), + }) \ No newline at end of file