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:
parent
4cfbd22cf2
commit
a18536dd5f
1 changed files with 5 additions and 5 deletions
|
|
@ -1,15 +1,16 @@
|
||||||
import { NextResponse } from "next/server"
|
import { NextRequest, NextResponse } from "next/server"
|
||||||
import type { Id } from "@/convex/_generated/dataModel"
|
import type { Id } from "@/convex/_generated/dataModel"
|
||||||
import { api } from "@/convex/_generated/api"
|
import { api } from "@/convex/_generated/api"
|
||||||
import { createConvexClient, ConvexConfigurationError } from "@/server/convex-client"
|
import { createConvexClient, ConvexConfigurationError } from "@/server/convex-client"
|
||||||
|
|
||||||
export const dynamic = "force-dynamic"
|
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 {
|
try {
|
||||||
const client = createConvexClient()
|
const client = createConvexClient()
|
||||||
const id = params.id as Id<"machines">
|
const { id } = await ctx.params
|
||||||
const data = (await client.query(api.machines.getById, { id, includeMetadata: true })) as unknown
|
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 })
|
if (!data) return NextResponse.json({ error: "Not found" }, { status: 404 })
|
||||||
return NextResponse.json(data, { status: 200 })
|
return NextResponse.json(data, { status: 200 })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -20,4 +21,3 @@ export async function GET(_req: Request, { params }: { params: { id: string } })
|
||||||
return NextResponse.json({ error: "Internal error" }, { status: 500 })
|
return NextResponse.json({ error: "Internal error" }, { status: 500 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue