fix: await params in Next.js 16 routes and pages for TypeScript compatibility
This commit is contained in:
@@ -10,10 +10,11 @@ import { hasRole } from "@/lib/permissions";
|
||||
*/
|
||||
export async function PATCH(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const playerId = parseInt(params.id);
|
||||
const { id } = await params
|
||||
const playerId = parseInt(id);
|
||||
|
||||
// Validate player ID
|
||||
if (isNaN(playerId)) {
|
||||
|
||||
@@ -8,10 +8,11 @@ const K_FACTOR = 32; // Standard K-factor for Elo calculations
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const tournamentId = parseInt(params.id, 10);
|
||||
const { id } = await params
|
||||
const tournamentId = parseInt(id, 10);
|
||||
|
||||
if (isNaN(tournamentId)) {
|
||||
return NextResponse.json(
|
||||
|
||||
@@ -4,10 +4,11 @@ import { canManageTournament } from "@/lib/permissions";
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const tournamentId = parseInt(params.id, 10);
|
||||
const { id } = await params
|
||||
const tournamentId = parseInt(id, 10);
|
||||
|
||||
if (isNaN(tournamentId)) {
|
||||
return NextResponse.json(
|
||||
|
||||
@@ -4,9 +4,9 @@ import { canManageTournament, canDeleteTournament } from "@/lib/permissions";
|
||||
import { getTournamentStatus } from "@/lib/tournamentUtils";
|
||||
|
||||
interface RouteParams {
|
||||
params: {
|
||||
params: Promise<{
|
||||
id: string;
|
||||
};
|
||||
}>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -16,7 +16,8 @@ interface RouteParams {
|
||||
*/
|
||||
export async function GET(request: Request, { params }: RouteParams) {
|
||||
try {
|
||||
const tournamentId = parseInt(params.id);
|
||||
const { id } = await params
|
||||
const tournamentId = parseInt(id);
|
||||
|
||||
// Validate tournament ID
|
||||
if (isNaN(tournamentId)) {
|
||||
@@ -105,7 +106,8 @@ export async function GET(request: Request, { params }: RouteParams) {
|
||||
*/
|
||||
export async function PUT(request: Request, { params }: RouteParams) {
|
||||
try {
|
||||
const tournamentId = parseInt(params.id);
|
||||
const { id } = await params
|
||||
const tournamentId = parseInt(id);
|
||||
|
||||
// Validate tournament ID
|
||||
if (isNaN(tournamentId)) {
|
||||
@@ -219,7 +221,8 @@ export async function PUT(request: Request, { params }: RouteParams) {
|
||||
*/
|
||||
export async function DELETE(request: Request, { params }: RouteParams) {
|
||||
try {
|
||||
const tournamentId = parseInt(params.id);
|
||||
const { id } = await params
|
||||
const tournamentId = parseInt(id);
|
||||
|
||||
// Validate tournament ID
|
||||
if (isNaN(tournamentId)) {
|
||||
|
||||
@@ -5,9 +5,10 @@ import { canAssignTournamentAdmin } from '@/lib/permissions';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const session = await getSession();
|
||||
|
||||
if (!session) {
|
||||
@@ -25,12 +26,12 @@ export async function GET(
|
||||
return NextResponse.json({ error: 'Requesting user not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
if (session.user.id !== params.id && requestingUser.role !== 'club_admin') {
|
||||
if (session.user.id !== id && requestingUser.role !== 'club_admin') {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
select: { role: true }
|
||||
});
|
||||
|
||||
@@ -46,9 +47,10 @@ export async function GET(
|
||||
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
// Check if the current user has permission to assign roles
|
||||
const permission = await canAssignTournamentAdmin();
|
||||
if (!permission.allowed) {
|
||||
|
||||
@@ -5,9 +5,10 @@ import { canEditUserProfiles } from '@/lib/permissions';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const session = await getSession();
|
||||
|
||||
if (!session) {
|
||||
@@ -25,13 +26,13 @@ export async function GET(
|
||||
}
|
||||
|
||||
// Allow if requesting own profile or if user is club_admin
|
||||
const canView = session.user.id === params.id || requestingUser.role === 'club_admin';
|
||||
const canView = session.user.id === id || requestingUser.role === 'club_admin';
|
||||
if (!canView) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
include: {
|
||||
player: true,
|
||||
}
|
||||
@@ -49,9 +50,10 @@ export async function GET(
|
||||
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const session = await getSession();
|
||||
|
||||
if (!session) {
|
||||
|
||||
Reference in New Issue
Block a user