Files
FlorteSite/src/app/api/threads/route.ts
T
faumaray 75e03b42f7 init
Signed-off-by: faumaray <faumaray@gmail.com>
2026-05-04 08:30:15 +03:00

33 lines
875 B
TypeScript

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);
}
}