haixunMaster/app/api/automation/logs/route.ts

20 lines
664 B
TypeScript

import { NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { getActiveAccountId } from "@/lib/account-context";
import { apiRouteErrorResponse } from "@/lib/auth/api";
import { requireUserAccountScope } from "@/lib/auth/user-scope";
export async function GET() {
try {
const accountId = await getActiveAccountId();
const { where } = await requireUserAccountScope(accountId);
const logs = await prisma.actionLog.findMany({
where,
orderBy: { createdAt: "desc" },
take: 60,
});
return NextResponse.json({ logs });
} catch (error) {
return apiRouteErrorResponse(error, "automation/logs");
}
}