import db from "@/lib/db"; import { NextResponse } from "next/server"; export async function POST(req) { const { project_id, task_id, note } = await req.json(); if (!note || (!project_id && !task_id)) { return NextResponse.json({ error: "Missing fields" }, { status: 400 }); } db.prepare( ` INSERT INTO notes (project_id, task_id, note) VALUES (?, ?, ?) ` ).run(project_id || null, task_id || null, note); return NextResponse.json({ success: true }); } export async function DELETE(_, { params }) { const { id } = params; db.prepare("DELETE FROM notes WHERE note_id = ?").run(id); return NextResponse.json({ success: true }); } export async function PUT(req, { params }) { const noteId = params.id; const { note } = await req.json(); if (!note || !noteId) { return NextResponse.json({ error: "Missing note or ID" }, { status: 400 }); } db.prepare( ` UPDATE notes SET note = ? WHERE note_id = ? ` ).run(note, noteId); return NextResponse.json({ success: true }); }