fix(api): Next.js 16 route handler types — params is Promise in context

- Update GET signature to (req: NextRequest, ctx: { params: Promise<{id:string}> })
- Await ctx.params and pass id to Convex client
- Keeps NextResponse return type
This commit is contained in:
codex-bot 2025-10-22 09:46:50 -03:00
parent 4cfbd22cf2
commit a18536dd5f

View file

@ -1,15 +1,16 @@
import { NextResponse } from "next/server"
import { NextRequest, NextResponse } from "next/server"
import type { Id } from "@/convex/_generated/dataModel"
import { api } from "@/convex/_generated/api"
import { createConvexClient, ConvexConfigurationError } from "@/server/convex-client"
export const dynamic = "force-dynamic"
export async function GET(_req: Request, { params }: { params: { id: string } }) {
export async function GET(_req: NextRequest, ctx: { params: Promise<{ id: string }> }) {
try {
const client = createConvexClient()
const id = params.id as Id<"machines">
const data = (await client.query(api.machines.getById, { id, includeMetadata: true })) as unknown
const { id } = await ctx.params
const machineId = id as Id<"machines">
const data = (await client.query(api.machines.getById, { id: machineId, includeMetadata: true })) as unknown
if (!data) return NextResponse.json({ error: "Not found" }, { status: 404 })
return NextResponse.json(data, { status: 200 })
} catch (err) {
@ -20,4 +21,3 @@ export async function GET(_req: Request, { params }: { params: { id: string } })
return NextResponse.json({ error: "Internal error" }, { status: 500 })
}
}