import { eq } from 'drizzle-orm' import { z } from 'zod' const schema = z.object({ title: z.string(), synopsis: z.string(), brief: z.string(), writerAgentId: z.string().nullable(), writerLocked: z.boolean(), summary: z.string(), reviewNotes: z.string() }) export default defineEventHandler(async (event) => { const chapter = getChapter(param(event)) const body = await readPatch(event, schema) const patch: Partial = { ...body } // 手动填写简报后,章节进入“已出简报”状态 if (body.brief !== undefined && chapter.status === 'planned' && body.brief.trim()) patch.status = 'briefed' if (body.brief !== undefined && chapter.status === 'briefed' && !body.brief.trim()) patch.status = 'planned' const row = useDb().update(tables.chapters).set(patch).where(eq(tables.chapters.id, chapter.id)).returning().get() emitProject(chapter.projectId, { type: 'chapter', chapterId: chapter.id }) return row })