From e46220c0dba44ee729f7131233114213b8a801b6 Mon Sep 17 00:00:00 2001 From: Pongrawee Sripetpong Date: Wed, 27 Nov 2024 23:09:54 +0700 Subject: [PATCH] Merge branch 'main' of https://github.com/Celesca/hacka-backend-elysia into owen --- src/controllers/teamController.ts | 111 ++++++------------------------ 1 file changed, 21 insertions(+), 90 deletions(-) diff --git a/src/controllers/teamController.ts b/src/controllers/teamController.ts index 7800cab..ae9fd3b 100644 --- a/src/controllers/teamController.ts +++ b/src/controllers/teamController.ts @@ -8,33 +8,12 @@ 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 }) => { +// Get TeamID from name and hackathon +.get("/find", async ({ query: { teamName, hackathonID }, error }) => { const team = await prisma.team.findFirst({ where: { - TeamID: TeamID, + TeamName: teamName, + HackathonID: hackathonID, }, }); @@ -45,77 +24,29 @@ export const teamController = new Elysia({ prefix: "/team" }) return team; }, { query: t.Object({ - TeamID: t.Number(), - }), -}) - -<<<<<<< HEAD -.get("/findteambyuser/:userID", async ({ params, error }) => { - - const team = await prisma.userTeam.findMany({ - where: { - UserID: params.userID, - }, - }); - - if (!team || team.length === 0) { - return error(404, "Team not found"); - } - - return team; -}, { - params: t.Object({ - userID: t.String(), // userID is a string in the URL params + teamName: t.String(), + hackathonID: t.Number(), }), }) +// .get("/findteambyuser/:userID", async ({ params, error }) => { -======= -// 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, - }, - }); +// const team = await prisma.userTeam.findMany({ +// where: { +// UserID: params.userID, +// }, +// }); - if (!team) { - return error(404, "Team not found"); - } +// if (!team || team.length === 0) { +// return error(404, "Team not found"); +// } - return {TeamID: team.TeamID}; - }, { - query: t.Object({ - TeamName: t.String(), - }), - }) ->>>>>>> 0c457d5157841e83fd2b56984d6e5332b4c37aeb +// return team; +// }, { +// params: t.Object({ +// userID: t.String(), // userID is a string in the URL params +// }), +// }) .get("/finduserteam/:teamID", async ({ params, error }) => { const teamID = parseInt(params.teamID, 10); // Ensure teamID is a number if (isNaN(teamID)) {