Files
vfxreview/app/api/dashboard/stats/route.ts
T
twotalesanimation 4f7e2a4adc
Deploy / deploy (push) Successful in 2m35s
API Updates
2026-07-08 16:03:57 +02:00

58 lines
1.3 KiB
TypeScript

import { NextResponse } from "next/server";
import { auth } from "@/auth";
import { db } from "@/lib/db";
export async function GET(req: Request) {
// Accept either a logged-in session or the shared display API key
const displayKey = process.env.API_SECRET_KEY;
const providedKey = req.headers.get("x-display-key");
const isDisplayDevice = displayKey && providedKey === displayKey;
if (!isDisplayDevice) {
const session = await auth();
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
}
const [
approved,
review,
changes,
todo,
artists,
shots,
renderQueue,
] = await Promise.all([
db.shot.count({
where: { shotApprovalStatus: "CLIENT_APPROVED" },
}),
db.shot.count({
where: { status: { in: ["INTERNAL_REVIEW", "READY_FOR_CLIENT", "CLIENT_REVIEW"] } },
}),
db.shot.count({
where: { status: "REVISIONS" },
}),
db.shot.count({
where: { status: "WAITING" },
}),
db.user.count({
where: { role: "ARTIST", isActive: true },
}),
db.shot.count({}),
db.task.count({
where: { type: "RENDER", status: { not: "DONE" } },
}),
]);
return NextResponse.json({
approved,
review,
changes,
todo,
artists,
shots,
renderQueue,
});
}