[taskboard] migrate fleet console to nextjs
This commit is contained in:
29
app/api/agents/[slug]/assign/route.ts
Normal file
29
app/api/agents/[slug]/assign/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { listFleetAgents } from "@/lib/agents";
|
||||
import { findTask, updateTask } from "@/lib/tasks";
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ slug: string }> },
|
||||
) {
|
||||
const { slug } = await params;
|
||||
const payload = (await request.json()) as { taskId?: number };
|
||||
if (!payload.taskId) {
|
||||
return NextResponse.json({ error: "taskId_is_required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const agents = await listFleetAgents();
|
||||
const agent = agents.find((entry) => entry.slug === slug);
|
||||
if (!agent) {
|
||||
return NextResponse.json({ error: "agent_not_found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const existing = await findTask(payload.taskId);
|
||||
if (!existing) {
|
||||
return NextResponse.json({ error: "task_not_found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const updated = await updateTask(existing.id, { assignee: agent.assignmentKey });
|
||||
return NextResponse.json({ success: true, task: updated });
|
||||
}
|
||||
7
app/api/agents/route.ts
Normal file
7
app/api/agents/route.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { listFleetAgents } from "@/lib/agents";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(await listFleetAgents());
|
||||
}
|
||||
Reference in New Issue
Block a user