33 lines
763 B
TypeScript
33 lines
763 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
/**
|
|
* GET /api/players
|
|
*
|
|
* Get all players with their user associations
|
|
* This is a public endpoint (no authentication required)
|
|
*/
|
|
export async function GET() {
|
|
try {
|
|
const players = await prisma.player.findMany({
|
|
include: {
|
|
user: {
|
|
select: {
|
|
email: true,
|
|
},
|
|
},
|
|
},
|
|
orderBy: { name: "asc" },
|
|
});
|
|
|
|
return NextResponse.json(players);
|
|
} catch (error: unknown) {
|
|
console.error("Error fetching players:", error);
|
|
const message = error instanceof Error ? error.message : "Failed to fetch players";
|
|
return NextResponse.json(
|
|
{ error: message },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|