feat: Implement task notes functionality with CRUD operations and integrate into project tasks section

This commit is contained in:
Chop
2025-06-03 20:46:37 +02:00
parent a9afebdda5
commit 330744daf9
9 changed files with 309 additions and 20 deletions

View File

@@ -0,0 +1,73 @@
import {
getNotesByTaskId,
addNoteToTask,
deleteNote,
} from "@/lib/queries/notes";
import { NextResponse } from "next/server";
// GET: Get notes for a specific task
export async function GET(req) {
const { searchParams } = new URL(req.url);
const taskId = searchParams.get("task_id");
if (!taskId) {
return NextResponse.json({ error: "task_id is required" }, { status: 400 });
}
try {
const notes = getNotesByTaskId(taskId);
return NextResponse.json(notes);
} catch (error) {
console.error("Error fetching task notes:", error);
return NextResponse.json(
{ error: "Failed to fetch task notes" },
{ status: 500 }
);
}
}
// POST: Add a note to a task
export async function POST(req) {
try {
const { task_id, note } = await req.json();
if (!task_id || !note) {
return NextResponse.json(
{ error: "task_id and note are required" },
{ status: 400 }
);
}
addNoteToTask(task_id, note);
return NextResponse.json({ success: true });
} catch (error) {
console.error("Error adding task note:", error);
return NextResponse.json(
{ error: "Failed to add task note" },
{ status: 500 }
);
}
}
// DELETE: Delete a note
export async function DELETE(req) {
try {
const { searchParams } = new URL(req.url);
const noteId = searchParams.get("note_id");
if (!noteId) {
return NextResponse.json(
{ error: "note_id is required" },
{ status: 400 }
);
}
deleteNote(noteId);
return NextResponse.json({ success: true });
} catch (error) {
console.error("Error deleting note:", error);
return NextResponse.json(
{ error: "Failed to delete note" },
{ status: 500 }
);
}
}