mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
import { queryOne, query } from "../../../../lib/db";
|
|
import { getServerSession } from "next-auth/next";
|
|
import { authOptions } from "../../auth/[...nextauth]/route";
|
|
|
|
export async function GET({ params }) {
|
|
const session = await getServerSession(authOptions);
|
|
|
|
if (!session) {
|
|
return new Response(JSON.stringify({ error: "Unauthorized" }), {
|
|
status: 401,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const teamId = parseInt(params.teamId, 10);
|
|
if (isNaN(teamId)) {
|
|
return new Response(JSON.stringify({ error: "Invalid team ID" }), {
|
|
status: 400,
|
|
});
|
|
}
|
|
|
|
const team = await queryOne(
|
|
"SELECT id, name, code FROM teams WHERE id = ?",
|
|
[teamId]
|
|
);
|
|
|
|
if (!team) {
|
|
return new Response(JSON.stringify({ error: "Team not found" }), {
|
|
status: 404,
|
|
});
|
|
}
|
|
|
|
const members = await query(
|
|
"SELECT id, username FROM users WHERE team_id = ?",
|
|
[teamId]
|
|
);
|
|
|
|
return new Response(JSON.stringify({ team, members }), {
|
|
status: 200,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error("Team fetch error:", error);
|
|
return new Response(
|
|
JSON.stringify({ error: "Failed to fetch team details" }),
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|