feat: add thread status read views
This commit is contained in:
34
src/app/api/v1/projects/[projectId]/thread-status/route.ts
Normal file
34
src/app/api/v1/projects/[projectId]/thread-status/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { requireRequestSession } from "@/lib/boss-auth";
|
||||
import { readState } from "@/lib/boss-data";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
context: { params: Promise<{ projectId: string }> },
|
||||
) {
|
||||
const session = await requireRequestSession(request);
|
||||
if (!session) {
|
||||
return NextResponse.json({ ok: false, message: "UNAUTHORIZED" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { projectId } = await context.params;
|
||||
const state = await readState();
|
||||
const project = state.projects.find((item) => item.id === projectId);
|
||||
if (!project) {
|
||||
return NextResponse.json({ ok: false, message: "PROJECT_NOT_FOUND" }, { status: 404 });
|
||||
}
|
||||
|
||||
const threadStatusDocument =
|
||||
state.threadStatusDocuments.find((item) => item.projectId === projectId) ?? null;
|
||||
const recentProgressEvents = state.threadProgressEvents
|
||||
.filter((item) => item.projectId === projectId)
|
||||
.sort((a, b) => b.createdAt.localeCompare(a.createdAt))
|
||||
.slice(0, 5);
|
||||
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
projectId,
|
||||
threadStatusDocument,
|
||||
recentProgressEvents,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user