spb/note-spboucher-ai
Public
1import { z } from "zod";2import { handler, parseBody } from "@/lib/api";3import { createPage } from "@/lib/pages/service";4import { workingPaperTemplate } from "@/lib/research/template";5import { PAPER_STATUSES } from "@/lib/research/overview";6import { audit } from "@/lib/audit";7/** POST { title?, status?, venue? } → new research page (section research) with the LaTeX-ready starter template. */8export const POST = handler(async ({ req, ws, user }) => {9 const b = await parseBody(req, z.object({ title: z.string().max(300).optional(), status: z.enum(PAPER_STATUSES).optional(), venue: z.string().max(200).optional() }));10 const title = b.title?.trim() || "New working paper";11 const p = await createPage(ws.id, { title, section: "research", type: "research", icon: "🔬", content: workingPaperTemplate(title), properties: { status: b.status ?? "planning", ...(b.venue ? { venue: b.venue } : {}), tags: ["working-paper"] } });12 await audit(user.id, "page.create", { type: "page", id: p.id }, { title: p.title, kind: "working-paper" });13 return Response.json(p, { status: 201 });14});15