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