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
44
src/server/companies-sync.ts
Normal file
44
src/server/companies-sync.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { api } from "@/convex/_generated/api"
|
||||
import { createConvexClient, ConvexConfigurationError } from "./convex-client"
|
||||
|
||||
type EnsureParams = {
|
||||
tenantId: string
|
||||
slug: string
|
||||
name: string
|
||||
provisioningCode: string
|
||||
}
|
||||
|
||||
type RemoveParams = {
|
||||
tenantId: string
|
||||
slug: string
|
||||
}
|
||||
|
||||
export async function syncConvexCompany(params: EnsureParams): Promise<boolean> {
|
||||
try {
|
||||
const client = createConvexClient()
|
||||
const result = await client.mutation(api.companies.ensureProvisioned, params)
|
||||
return Boolean(result)
|
||||
} catch (error) {
|
||||
if (error instanceof ConvexConfigurationError) {
|
||||
console.warn("[companies-sync] Convex não configurado; sincronização ignorada.")
|
||||
return false
|
||||
}
|
||||
console.error("[companies-sync] Falha ao sincronizar empresa no Convex", error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export async function removeConvexCompany(params: RemoveParams): Promise<boolean> {
|
||||
try {
|
||||
const client = createConvexClient()
|
||||
const result = await client.mutation(api.companies.removeBySlug, params)
|
||||
return Boolean(result?.removed ?? true)
|
||||
} catch (error) {
|
||||
if (error instanceof ConvexConfigurationError) {
|
||||
console.warn("[companies-sync] Convex não configurado; remoção ignorada.")
|
||||
return false
|
||||
}
|
||||
console.error("[companies-sync] Falha ao remover empresa no Convex", error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue