admin(machines): add resilient fallback for details page

- Keep Convex useQuery for machines.getById
- Add HTTP fallback via /api/admin/machines/[id]/details if query stays loading (>1.2s)
- Helps when websocket/convex-react doesn’t initialize and avoids permanent skeleton
This commit is contained in:
codex-bot 2025-10-22 09:39:51 -03:00
parent e0f65cc774
commit 4cfbd22cf2
2 changed files with 54 additions and 5 deletions

View file

@ -0,0 +1,23 @@
import { 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 } }) {
try {
const client = createConvexClient()
const id = params.id as Id<"machines">
const data = (await client.query(api.machines.getById, { id, includeMetadata: true })) as unknown
if (!data) return NextResponse.json({ error: "Not found" }, { status: 404 })
return NextResponse.json(data, { status: 200 })
} catch (err) {
if (err instanceof ConvexConfigurationError) {
return NextResponse.json({ error: err.message }, { status: 500 })
}
console.error("[api] admin/machines/[id]/details error", err)
return NextResponse.json({ error: "Internal error" }, { status: 500 })
}
}