import { z } from "zod"; import { withUser, parseBody, json } from "@/lib/api"; import { listFolders, createFolder, updateFolder, deleteFolder } from "@/lib/conversations/service"; export const dynamic = "force-dynamic"; export const GET = withUser(async ({ user }) => json({ folders: await listFolders(user.id) })); export const POST = withUser(async ({ req, user }) => { const body = await parseBody(req, z.object({ name: z.string().min(1).max(80), color: z.string().max(20).nullable().optional() })); return json({ folder: await createFolder(user.id, body.name, body.color) }, { status: 201 }); }); export const PATCH = withUser(async ({ req, user }) => { const body = await parseBody(req, z.object({ id: z.string().max(64), name: z.string().min(1).max(80).optional(), color: z.string().max(20).nullable().optional(), sortOrder: z.number().int().optional() })); const { id, ...patch } = body; return json({ folder: await updateFolder(user.id, id, patch) }); }); export const DELETE = withUser(async ({ req, user }) => { const id = new URL(req.url).searchParams.get("id"); if (id) await deleteFolder(user.id, id); return json({ ok: true }); });