import { NextRequest, NextResponse } from 'next/server' import { auth } from '@/auth' import { updateTask, deleteTask } from '@/lib/vikunja-client' export async function PATCH( request: NextRequest, { params }: { params: Promise<{ id: string }> } ) { const session = await auth() if (!session?.user) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) } try { const { id } = await params const taskId = parseInt(id, 10) const body = await request.json() const task = await updateTask(taskId, body) return NextResponse.json(task) } catch (error) { const message = error instanceof Error ? error.message : 'Failed to update task' return NextResponse.json({ error: message }, { status: 502 }) } } export async function DELETE( _request: NextRequest, { params }: { params: Promise<{ id: string }> } ) { const session = await auth() if (!session?.user) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) } try { const { id } = await params const taskId = parseInt(id, 10) await deleteTask(taskId) return NextResponse.json({ success: true }) } catch (error) { const message = error instanceof Error ? error.message : 'Failed to delete task' return NextResponse.json({ error: message }, { status: 502 }) } }