[taskboard] migrate fleet console to nextjs
This commit is contained in:
35
app/api/tasks/[id]/route.ts
Normal file
35
app/api/tasks/[id]/route.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { updateTask, validateTaskPayload } from "@/lib/tasks";
|
||||
|
||||
export async function PATCH(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
const numericId = Number(id);
|
||||
if (!Number.isInteger(numericId) || numericId <= 0) {
|
||||
return NextResponse.json({ error: "invalid_task_id" }, { status: 400 });
|
||||
}
|
||||
|
||||
const payload = (await request.json()) as Record<string, unknown>;
|
||||
const errors = validateTaskPayload(payload as never, true);
|
||||
if (errors.length > 0) {
|
||||
return NextResponse.json({ error: "validation_error", details: errors }, { status: 400 });
|
||||
}
|
||||
|
||||
const task = await updateTask(numericId, {
|
||||
title: typeof payload.title === "string" ? payload.title : undefined,
|
||||
description: typeof payload.description === "string" ? payload.description : undefined,
|
||||
assignee: typeof payload.assignee === "string" ? payload.assignee : undefined,
|
||||
priority: payload.priority as never,
|
||||
status: payload.status as never,
|
||||
tags: Array.isArray(payload.tags) ? payload.tags.filter((tag) => typeof tag === "string") : undefined,
|
||||
});
|
||||
|
||||
if (!task) {
|
||||
return NextResponse.json({ error: "task_not_found" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json(task);
|
||||
}
|
||||
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