This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@/auth";
|
||||
import { db } from "@/lib/db";
|
||||
|
||||
/** GET /api/projects/[projectId]/episodes — returns distinct episode values for shots in a project */
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ projectId: string }> }
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { projectId } = await params;
|
||||
|
||||
const shots = await db.shot.findMany({
|
||||
where: { projectId, episode: { not: null } },
|
||||
select: { episode: true },
|
||||
distinct: ["episode"],
|
||||
orderBy: { episode: "asc" },
|
||||
});
|
||||
|
||||
const episodes = shots
|
||||
.map((s) => s.episode as string)
|
||||
.filter(Boolean);
|
||||
|
||||
return NextResponse.json({ episodes });
|
||||
}
|
||||
Reference in New Issue
Block a user