import { prisma } from "@/lib/db"; import { requireDm } from "@/lib/session"; import { json, err, asResponse } from "@/lib/api"; export const dynamic = "force-dynamic"; export async function GET() { try { await requireDm(); const rows = await prisma.thread.findMany({ where: { resolved: false }, orderBy: [{ primary: "desc" }, { createdAt: "desc" }], }); return json(rows); } catch (e) { return asResponse(e); } } export async function POST(req: Request) { try { await requireDm(); const b = (await req.json()) as Partial<{ text: string; who: string; primary: boolean }>; if (!b.text) return err("text required"); const t = await prisma.thread.create({ data: { text: b.text, who: b.who ?? "", primary: !!b.primary }, }); return json(t, { status: 201 }); } catch (e) { return asResponse(e); } }