feat: sync convex companies and dashboard metrics
This commit is contained in:
parent
4f52114b48
commit
7a3eca9361
10 changed files with 356 additions and 19 deletions
|
|
@ -5,6 +5,7 @@ import { prisma } from "@/lib/prisma"
|
|||
import { assertStaffSession } from "@/lib/auth-server"
|
||||
import { isAdmin } from "@/lib/authz"
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library"
|
||||
import { syncConvexCompany } from "@/server/companies-sync"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
|
|
@ -64,6 +65,19 @@ export async function POST(request: Request) {
|
|||
address: address ? String(address) : null,
|
||||
},
|
||||
})
|
||||
|
||||
if (company.provisioningCode) {
|
||||
const synced = await syncConvexCompany({
|
||||
tenantId: company.tenantId,
|
||||
slug: company.slug,
|
||||
name: company.name,
|
||||
provisioningCode: company.provisioningCode,
|
||||
})
|
||||
if (!synced) {
|
||||
console.warn("[admin.companies] Convex não configurado; empresa criada apenas no Prisma.")
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({ company })
|
||||
} catch (error) {
|
||||
console.error("Failed to create company", error)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue