Skip to content

Commit

Permalink
update rating
Browse files Browse the repository at this point in the history
  • Loading branch information
satanakorn committed Nov 27, 2024
1 parent 549e622 commit a5ec4f0
Showing 1 changed file with 115 additions and 74 deletions.
189 changes: 115 additions & 74 deletions src/controllers/teamController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -306,4 +260,91 @@ export const teamController = new Elysia({ prefix: "/team" })
teamID: t.Number(),
userID: t.String(),
}),
})
})


// 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(),
}),
})

0 comments on commit a5ec4f0

Please sign in to comment.