39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { NextResponse } from "next/server"
|
|
import { fetchAction } from "convex/nextjs"
|
|
import { api } from "@/convex/_generated/api"
|
|
import { requireAdminToken } from "@/lib/server/admin-auth"
|
|
|
|
export async function POST(request: Request) {
|
|
const authError = requireAdminToken(request)
|
|
if (authError) {
|
|
return authError
|
|
}
|
|
|
|
try {
|
|
const body = await request.json().catch(() => ({}))
|
|
const result = await fetchAction(api.crm.runGhlMirror, {
|
|
reason: "admin",
|
|
forceFullBackfill: Boolean(body.forceFullBackfill),
|
|
maxPagesPerRun:
|
|
typeof body.maxPagesPerRun === "number" ? body.maxPagesPerRun : undefined,
|
|
contactsLimit:
|
|
typeof body.contactsLimit === "number" ? body.contactsLimit : undefined,
|
|
messagesLimit:
|
|
typeof body.messagesLimit === "number" ? body.messagesLimit : undefined,
|
|
recordingsPageSize:
|
|
typeof body.recordingsPageSize === "number"
|
|
? body.recordingsPageSize
|
|
: undefined,
|
|
})
|
|
|
|
return NextResponse.json(result)
|
|
} catch (error) {
|
|
console.error("Failed to run admin GHL sync:", error)
|
|
return NextResponse.json(
|
|
{
|
|
error: error instanceof Error ? error.message : "Failed to run GHL sync",
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|