Multi-tenant platform (182 pages, 228 API routes, ~30 modules) built on a deterministic verification core: clinical-trial claims checked against ClinicalTrials.gov registered results and raw event counts (ARR/NNT/RR+CI recomputed in code, oracle-tested), code-enforced exact-span grounding, and multi-source cross-verification. Auth/RBAC/multi-tenancy, document processing at scale (unpdf + Docling), agentic workflows, Claude Science connector, compliance/audit, billing, public API, and more. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import type { NextRequest } from "next/server";
|
|
import { getPool } from "@/lib/db";
|
|
import { withOrg, type Ctx } from "@/lib/api/handler";
|
|
import { created, fail } from "@/lib/api/response";
|
|
import { requireRole } from "@/lib/authz/rbac";
|
|
import { writeAudit } from "@/lib/audit";
|
|
import { createFeedbackSchema } from "@/lib/help/types";
|
|
import { createFeedback } from "@/lib/help/queries";
|
|
|
|
// POST /api/feedback — submit lightweight product feedback (bug/idea/praise/other).
|
|
// Any member (viewer+) may submit. Audited (message omitted from metadata to keep
|
|
// free-text out of the audit log).
|
|
export const POST = withOrg(async (req: NextRequest, ctx: Ctx) => {
|
|
try {
|
|
requireRole(ctx, "viewer");
|
|
const raw = await req.json().catch(() => null);
|
|
const parsed = createFeedbackSchema.safeParse(raw);
|
|
if (!parsed.success) {
|
|
return fail(parsed.error.issues[0]?.message ?? "Invalid input.", 400);
|
|
}
|
|
|
|
const pool = getPool();
|
|
const entry = await createFeedback(pool, {
|
|
orgId: ctx.org.id,
|
|
userId: ctx.user.id,
|
|
kind: parsed.data.kind,
|
|
message: parsed.data.message,
|
|
});
|
|
|
|
await writeAudit(pool, {
|
|
orgId: ctx.org.id,
|
|
userId: ctx.user.id,
|
|
action: "feedback.create",
|
|
entityType: "feedback",
|
|
entityId: entry.id,
|
|
metadata: { kind: entry.kind },
|
|
});
|
|
|
|
return created(entry);
|
|
} catch (err: unknown) {
|
|
if (err instanceof Error && "status" in err) {
|
|
return fail(err.message, (err as { status: number }).status);
|
|
}
|
|
return fail("Failed to submit feedback.", 500);
|
|
}
|
|
});
|