Hours by client: add search and CSV filtering; add alerts cron (BRT 08:00 guard) + alerts panel filters; admin companies shows last alert; PDF Inter font from public/fonts; fix Select empty value; type cleanups; tests for CSV/TZ; remove Knowledge Base nav
This commit is contained in:
parent
2cf399dcb1
commit
08cc8037d5
151 changed files with 1404 additions and 214 deletions
37
src/app/api/admin/companies/last-alerts/route.ts
Normal file
37
src/app/api/admin/companies/last-alerts/route.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { NextResponse } from "next/server"
|
||||
import { ConvexHttpClient } from "convex/browser"
|
||||
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { env } from "@/lib/env"
|
||||
import { assertAdminSession } from "@/lib/auth-server"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const session = await assertAdminSession()
|
||||
if (!session) return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
|
||||
|
||||
const convexUrl = env.NEXT_PUBLIC_CONVEX_URL
|
||||
if (!convexUrl) return NextResponse.json({ error: "Convex não configurado" }, { status: 500 })
|
||||
const client = new ConvexHttpClient(convexUrl)
|
||||
|
||||
const { searchParams } = new URL(request.url)
|
||||
const slugsParam = searchParams.get("slugs")
|
||||
if (!slugsParam) return NextResponse.json({ items: {} })
|
||||
const slugs = slugsParam.split(",").map((s) => s.trim()).filter(Boolean)
|
||||
|
||||
const tenantId = session.user.tenantId ?? "tenant-atlas"
|
||||
const result: Record<string, { createdAt: number; usagePct: number; threshold: number } | null> = {}
|
||||
for (const slug of slugs) {
|
||||
try {
|
||||
const last = (await client.query(api.alerts.lastForCompanyBySlug, { tenantId, slug })) as
|
||||
| { createdAt: number; usagePct: number; threshold: number }
|
||||
| null
|
||||
result[slug] = last
|
||||
} catch {
|
||||
result[slug] = null
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({ items: result })
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue