[taskboard] migrate fleet console to nextjs
This commit is contained in:
26
app/api/tasks/route.ts
Normal file
26
app/api/tasks/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { createTask, listTasks, validateTaskPayload } from "@/lib/tasks";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(await listTasks());
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const payload = (await request.json()) as Record<string, unknown>;
|
||||
const errors = validateTaskPayload(payload as never, false);
|
||||
if (errors.length > 0) {
|
||||
return NextResponse.json({ error: "validation_error", details: errors }, { status: 400 });
|
||||
}
|
||||
|
||||
const task = await createTask({
|
||||
title: String(payload.title),
|
||||
description: typeof payload.description === "string" ? payload.description : "",
|
||||
assignee: typeof payload.assignee === "string" ? payload.assignee : "",
|
||||
priority: payload.priority as never,
|
||||
status: (payload.status as never) || "Backlog",
|
||||
tags: Array.isArray(payload.tags) ? payload.tags.filter((tag) => typeof tag === "string") : [],
|
||||
});
|
||||
|
||||
return NextResponse.json(task, { status: 201 });
|
||||
}
|
||||
Reference in New Issue
Block a user