import db from "@/lib/db"; import { NextResponse } from "next/server"; import { withUserAuth, withReadAuth } from "@/lib/middleware/auth"; import { getAllTaskTemplates } from "@/lib/queries/tasks"; // POST: create new template async function createTaskHandler(req) { const { name, max_wait_days, description, task_category } = await req.json(); if (!name) { return NextResponse.json({ error: "Name is required" }, { status: 400 }); } if (!task_category || !['design', 'construction'].includes(task_category)) { return NextResponse.json({ error: "Valid task_category is required (design or construction)" }, { status: 400 }); } db.prepare( ` INSERT INTO tasks (name, max_wait_days, description, is_standard, task_category) VALUES (?, ?, ?, 1, ?) ` ).run(name, max_wait_days || 0, description || null, task_category); return NextResponse.json({ success: true }); } // GET: Get all task templates async function getTasksHandler(req) { const templates = getAllTaskTemplates(); return NextResponse.json(templates); } // Protected routes - require authentication export const GET = withReadAuth(getTasksHandler); export const POST = withUserAuth(createTaskHandler);