@@ -0,0 +1,22 @@
|
||||
import { auth } from "@/auth";
|
||||
import { redirect } from "next/navigation";
|
||||
import { db } from "@/lib/db";
|
||||
import { ShootLogClient } from "@/components/shoot-log/ShootLogClient";
|
||||
|
||||
export const metadata = { title: "Shot Log" };
|
||||
|
||||
export default async function ShootLogPage() {
|
||||
const session = await auth();
|
||||
if (!session?.user) redirect("/login");
|
||||
if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role)) {
|
||||
redirect("/dashboard");
|
||||
}
|
||||
|
||||
const projects = await db.project.findMany({
|
||||
where: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
||||
select: { id: true, name: true, code: true },
|
||||
orderBy: { name: "asc" },
|
||||
});
|
||||
|
||||
return <ShootLogClient projects={projects} />;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
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/[dayId]/setups
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ dayId: string }> }
|
||||
) {
|
||||
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 { dayId } = await params;
|
||||
|
||||
const setups = await db.setup.findMany({
|
||||
where: { shootDayId: dayId },
|
||||
orderBy: { sortOrder: "asc" },
|
||||
include: {
|
||||
takes: {
|
||||
orderBy: { takeNumber: "asc" },
|
||||
include: { _count: { select: { attachments: true } } },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ setups });
|
||||
}
|
||||
|
||||
// POST /api/shoot-log/days/[dayId]/setups
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ dayId: string }> }
|
||||
) {
|
||||
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 { dayId } = await params;
|
||||
const body = await req.json();
|
||||
const { name, description } = body;
|
||||
if (!name) return NextResponse.json({ error: "name required" }, { status: 400 });
|
||||
|
||||
const last = await db.setup.findFirst({
|
||||
where: { shootDayId: dayId },
|
||||
orderBy: { sortOrder: "desc" },
|
||||
});
|
||||
|
||||
const setup = await db.setup.create({
|
||||
data: {
|
||||
shootDayId: dayId,
|
||||
name,
|
||||
description: description ?? null,
|
||||
sortOrder: (last?.sortOrder ?? -1) + 1,
|
||||
},
|
||||
include: { takes: { orderBy: { takeNumber: "asc" }, include: { _count: { select: { attachments: true } } } } },
|
||||
});
|
||||
|
||||
return NextResponse.json({ setup }, { status: 201 });
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
@@ -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/recent-values?projectId=xxx
|
||||
// Returns recently used values for smart autofill on new takes
|
||||
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 });
|
||||
|
||||
// Fetch the 5 most recent takes for this project to extract autofill candidates
|
||||
const recentTakes = await db.take.findMany({
|
||||
where: {
|
||||
setup: { shootDay: { projectId } },
|
||||
},
|
||||
orderBy: { createdAt: "desc" },
|
||||
take: 5,
|
||||
select: {
|
||||
cameraModel: true,
|
||||
cameraLetter: true,
|
||||
resolution: true,
|
||||
codec: true,
|
||||
fps: true,
|
||||
shutter: true,
|
||||
iso: true,
|
||||
whiteBalance: true,
|
||||
colourSpace: true,
|
||||
lensSet: true,
|
||||
lens: true,
|
||||
filters: true,
|
||||
isAnamorphic: true,
|
||||
weather: true,
|
||||
clipName: true,
|
||||
},
|
||||
});
|
||||
|
||||
// Return the most recent non-null value for each field
|
||||
function latest<T>(field: keyof typeof recentTakes[0]): T | null {
|
||||
for (const take of recentTakes) {
|
||||
const v = take[field];
|
||||
if (v !== null && v !== undefined) return v as T;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
cameraModel: latest("cameraModel"),
|
||||
cameraLetter: latest("cameraLetter"),
|
||||
resolution: latest("resolution"),
|
||||
codec: latest("codec"),
|
||||
fps: latest("fps"),
|
||||
shutter: latest("shutter"),
|
||||
iso: latest("iso"),
|
||||
whiteBalance: latest("whiteBalance"),
|
||||
colourSpace: latest("colourSpace"),
|
||||
lensSet: latest("lensSet"),
|
||||
lens: latest("lens"),
|
||||
filters: latest("filters"),
|
||||
isAnamorphic: latest("isAnamorphic"),
|
||||
weather: latest("weather"),
|
||||
lastClipName: latest("clipName"),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
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/setups/[setupId]/takes
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ setupId: string }> }
|
||||
) {
|
||||
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 { setupId } = await params;
|
||||
|
||||
const takes = await db.take.findMany({
|
||||
where: { setupId },
|
||||
orderBy: { takeNumber: "asc" },
|
||||
include: { attachments: { orderBy: { sortOrder: "asc" } } },
|
||||
});
|
||||
|
||||
return NextResponse.json({ takes });
|
||||
}
|
||||
|
||||
// POST /api/shoot-log/setups/[setupId]/takes
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ setupId: string }> }
|
||||
) {
|
||||
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 { setupId } = await params;
|
||||
const body = await req.json();
|
||||
|
||||
const last = await db.take.findFirst({
|
||||
where: { setupId },
|
||||
orderBy: { takeNumber: "desc" },
|
||||
});
|
||||
const takeNumber = (last?.takeNumber ?? 0) + 1;
|
||||
|
||||
const take = await db.take.create({
|
||||
data: {
|
||||
setupId,
|
||||
takeNumber,
|
||||
createdById: session.user.id,
|
||||
...sanitize(body),
|
||||
},
|
||||
include: { attachments: { orderBy: { sortOrder: "asc" } } },
|
||||
});
|
||||
|
||||
return NextResponse.json({ take }, { status: 201 });
|
||||
}
|
||||
|
||||
function sanitize(data: Record<string, unknown>) {
|
||||
const allowed = new Set([
|
||||
"scene","shotLabel","unitLabel","cameraLetter","clipName","roll","cameraModel",
|
||||
"resolution","codec","fps","shutter","iso","whiteBalance","colourSpace",
|
||||
"lensSet","lens","tStop","filters","isAnamorphic",
|
||||
"hasHdri","hasChromeBall","hasGreyBall","hasMacbeth","hasCleanPlate",
|
||||
"hasSurvey","hasLidar","hasWitnessCamera","hasLensGrid","hasTexturePhotos","hasPhotogrammetry",
|
||||
"weather","sunDirection","artificialLights",
|
||||
"supervisorNotes","continuityNotes","vfxRequirements","quality",
|
||||
]);
|
||||
return Object.fromEntries(
|
||||
Object.entries(data)
|
||||
.filter(([k]) => allowed.has(k))
|
||||
.map(([k, v]) => [k, v === "" ? null : v])
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
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);
|
||||
}
|
||||
|
||||
// PATCH /api/shoot-log/takes/[takeId]/attachments/[attachmentId]
|
||||
export async function PATCH(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ takeId: string; attachmentId: string }> }
|
||||
) {
|
||||
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 { attachmentId } = await params;
|
||||
const { caption, category } = await req.json();
|
||||
|
||||
const attachment = await db.takeAttachment.update({
|
||||
where: { id: attachmentId },
|
||||
data: {
|
||||
...(caption !== undefined ? { caption } : {}),
|
||||
...(category !== undefined ? { category } : {}),
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ attachment });
|
||||
}
|
||||
|
||||
// DELETE /api/shoot-log/takes/[takeId]/attachments/[attachmentId]
|
||||
export async function DELETE(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ takeId: string; attachmentId: string }> }
|
||||
) {
|
||||
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 { attachmentId } = await params;
|
||||
await db.takeAttachment.delete({ where: { id: attachmentId } });
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@/auth";
|
||||
import { db } from "@/lib/db";
|
||||
import { AttachmentFileType, AttachmentCategory } from "@prisma/client";
|
||||
|
||||
function requireRole(role: string) {
|
||||
return ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(role);
|
||||
}
|
||||
|
||||
// GET /api/shoot-log/takes/[takeId]/attachments
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ takeId: string }> }
|
||||
) {
|
||||
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 { takeId } = await params;
|
||||
const attachments = await db.takeAttachment.findMany({
|
||||
where: { takeId },
|
||||
orderBy: { sortOrder: "asc" },
|
||||
include: { uploadedBy: { select: { id: true, name: true } } },
|
||||
});
|
||||
|
||||
return NextResponse.json({ attachments });
|
||||
}
|
||||
|
||||
// POST /api/shoot-log/takes/[takeId]/attachments
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ takeId: string }> }
|
||||
) {
|
||||
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 { takeId } = await params;
|
||||
const body = await req.json();
|
||||
const { fileUrl, fileKey, fileName, fileSize, fileType, category, caption } = body;
|
||||
|
||||
if (!fileUrl || !fileName) {
|
||||
return NextResponse.json({ error: "fileUrl and fileName required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const last = await db.takeAttachment.findFirst({
|
||||
where: { takeId },
|
||||
orderBy: { sortOrder: "desc" },
|
||||
});
|
||||
|
||||
const attachment = await db.takeAttachment.create({
|
||||
data: {
|
||||
takeId,
|
||||
fileUrl,
|
||||
fileKey: fileKey ?? "",
|
||||
fileName,
|
||||
fileSize: fileSize ? BigInt(fileSize) : undefined,
|
||||
fileType: (fileType as AttachmentFileType) ?? "IMAGE",
|
||||
category: (category as AttachmentCategory) ?? "MISCELLANEOUS",
|
||||
caption: caption ?? null,
|
||||
sortOrder: (last?.sortOrder ?? -1) + 1,
|
||||
uploadedById: session.user.id,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ attachment }, { status: 201 });
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
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);
|
||||
}
|
||||
|
||||
function sanitize(data: Record<string, unknown>) {
|
||||
const allowed = new Set([
|
||||
"scene","shotLabel","unitLabel","cameraLetter","clipName","roll","cameraModel",
|
||||
"resolution","codec","fps","shutter","iso","whiteBalance","colourSpace",
|
||||
"lensSet","lens","tStop","filters","isAnamorphic",
|
||||
"hasHdri","hasChromeBall","hasGreyBall","hasMacbeth","hasCleanPlate",
|
||||
"hasSurvey","hasLidar","hasWitnessCamera","hasLensGrid","hasTexturePhotos","hasPhotogrammetry",
|
||||
"weather","sunDirection","artificialLights",
|
||||
"supervisorNotes","continuityNotes","vfxRequirements","quality",
|
||||
]);
|
||||
return Object.fromEntries(
|
||||
Object.entries(data)
|
||||
.filter(([k]) => allowed.has(k))
|
||||
.map(([k, v]) => [k, v === "" ? null : v])
|
||||
);
|
||||
}
|
||||
|
||||
// GET /api/shoot-log/takes/[takeId]
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ takeId: string }> }
|
||||
) {
|
||||
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 { takeId } = await params;
|
||||
|
||||
const take = await db.take.findUnique({
|
||||
where: { id: takeId },
|
||||
include: {
|
||||
attachments: { orderBy: { sortOrder: "asc" } },
|
||||
setup: {
|
||||
include: {
|
||||
shootDay: { select: { id: true, date: true, unit: true, label: true, projectId: true } },
|
||||
takes: { orderBy: { takeNumber: "asc" }, select: { id: true, takeNumber: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!take) return NextResponse.json({ error: "Not found" }, { status: 404 });
|
||||
return NextResponse.json({ take });
|
||||
}
|
||||
|
||||
// PATCH /api/shoot-log/takes/[takeId]
|
||||
export async function PATCH(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ takeId: string }> }
|
||||
) {
|
||||
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 { takeId } = await params;
|
||||
const body = await req.json();
|
||||
|
||||
const take = await db.take.update({
|
||||
where: { id: takeId },
|
||||
data: sanitize(body),
|
||||
include: { attachments: { orderBy: { sortOrder: "asc" } } },
|
||||
});
|
||||
|
||||
return NextResponse.json({ take });
|
||||
}
|
||||
|
||||
// DELETE /api/shoot-log/takes/[takeId]
|
||||
export async function DELETE(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ takeId: string }> }
|
||||
) {
|
||||
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 { takeId } = await params;
|
||||
await db.take.delete({ where: { id: takeId } });
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
Reference in New Issue
Block a user