import { NextResponse } from 'next/server' import { db } from '@/lib/db' export const dynamic = 'force-dynamic' // GET /api/aos/tasks/[id]/comments — list comments on a task export async function GET( _req: Request, { params }: { params: Promise<{ id: string }> } ) { const { id } = await params const comments = await db.taskComment.findMany({ where: { taskId: id }, orderBy: { createdAt: 'asc' }, }) return NextResponse.json({ comments }) } // POST /api/aos/tasks/[id]/comments — add a comment export async function POST( req: Request, { params }: { params: Promise<{ id: string }> } ) { const { id } = await params const { body, author } = (await req.json()) as { body: string; author?: string } if (!body?.trim()) return NextResponse.json({ error: 'body required' }, { status: 400 }) const comment = await db.taskComment.create({ data: { taskId: id, body: body.trim(), author: author ?? 'Max Brandt' }, }) await db.auditLog.create({ data: { actor: author ?? 'max@nordlicht.digital', action: 'task.comment:create', entity: 'TaskComment', entityId: comment.id, after: JSON.stringify({ taskId: id, length: body.length }), hash: 'sha256:' + Math.random().toString(36).slice(2), }, }) return NextResponse.json({ comment }) }