36 lines
902 B
TypeScript
36 lines
902 B
TypeScript
import { NextResponse } from "next/server"
|
|
import { fetchQuery } from "convex/nextjs"
|
|
import { api } from "@/convex/_generated/api"
|
|
import { requireAdminToken } from "@/lib/server/admin-auth"
|
|
|
|
type RouteContext = {
|
|
params: Promise<{
|
|
id: string
|
|
}>
|
|
}
|
|
|
|
export async function GET(request: Request, { params }: RouteContext) {
|
|
const authError = requireAdminToken(request)
|
|
if (authError) {
|
|
return authError
|
|
}
|
|
|
|
try {
|
|
const { id } = await params
|
|
const detail = await fetchQuery(api.crm.getAdminContactDetail, {
|
|
contactId: id,
|
|
})
|
|
|
|
if (!detail) {
|
|
return NextResponse.json({ error: "Contact not found" }, { status: 404 })
|
|
}
|
|
|
|
return NextResponse.json(detail)
|
|
} catch (error) {
|
|
console.error("Failed to load admin contact detail:", error)
|
|
return NextResponse.json(
|
|
{ error: "Failed to load contact detail" },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|