Supervisor feature
Deploy / deploy (push) Successful in 3m5s

This commit is contained in:
twotalesanimation
2026-07-11 15:06:12 +02:00
parent 6fc818a3db
commit e24fd8eda0
19 changed files with 3175 additions and 2 deletions
+72
View File
@@ -0,0 +1,72 @@
import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/auth";
import { db } from "@/lib/db";
function requireRole(role: string) {
return ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(role);
}
// GET /api/shoot-log/days?projectId=xxx
export async function GET(req: NextRequest) {
const session = await auth();
if (!session?.user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
if (!requireRole(session.user.role))
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
const projectId = req.nextUrl.searchParams.get("projectId");
if (!projectId) return NextResponse.json({ error: "projectId required" }, { status: 400 });
const days = await db.shootDay.findMany({
where: { projectId },
orderBy: { date: "desc" },
include: {
setups: {
orderBy: { sortOrder: "asc" },
include: {
takes: {
orderBy: { takeNumber: "asc" },
include: {
_count: { select: { attachments: true } },
},
},
},
},
createdBy: { select: { id: true, name: true } },
},
});
return NextResponse.json({ days });
}
// POST /api/shoot-log/days
export async function POST(req: NextRequest) {
const session = await auth();
if (!session?.user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
if (!requireRole(session.user.role))
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
const body = await req.json();
const { projectId, date, unit, label, notes } = body;
if (!projectId || !date) {
return NextResponse.json({ error: "projectId and date required" }, { status: 400 });
}
const day = await db.shootDay.create({
data: {
projectId,
date: new Date(date),
unit: unit ?? "A",
label: label ?? null,
notes: notes ?? null,
createdById: session.user.id,
},
include: {
setups: {
orderBy: { sortOrder: "asc" },
include: { takes: { orderBy: { takeNumber: "asc" }, include: { _count: { select: { attachments: true } } } } },
},
},
});
return NextResponse.json({ day }, { status: 201 });
}