feat(deliveries): delivery requests and upload/share evidence
Deploy / deploy (push) Successful in 5m17s
Deploy / deploy (push) Successful in 5m17s
A built package used to become DELIVERED on one click with nothing behind it, and nothing recorded what a client had asked for. - Marking delivered is now two recorded steps: Record upload (the link on the client's portal, contents confirmed) then Share link (who it was sent to). The second is refused until the first is on record. - Delivery requests log a client's ask by episode, pasted shot codes or a Shot Status selection. A line closes only when its shot goes out with evidence after the request was logged; a request can otherwise only be cancelled with a reason. - Delivered Outside Pipeline takes an upload link and recipient, required for shots on an open request. - The dashboard gains an Awaiting delivery section listing open requests and built packages the client does not have yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,20 +2,30 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||
import { requirePipelineAdmin } from "@/lib/render-pipeline/session-auth";
|
||||
import { markDelivered } from "@/lib/render-pipeline/deliveries";
|
||||
import { recordShareSchema } from "@/lib/render-pipeline/delivery-handoff";
|
||||
|
||||
// ── POST /api/deliveries/{id}/delivered (E19) ────────────────────────────────
|
||||
//
|
||||
// The folder has been uploaded to the client. Moves every packaged export to
|
||||
// DELIVERED — the end of the pipeline.
|
||||
// The upload link has been sent to the client. Takes who it was sent to, and
|
||||
// moves every packaged export to DELIVERED — the end of the pipeline.
|
||||
|
||||
export async function POST(
|
||||
_req: NextRequest,
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ packageId: string }> }
|
||||
) {
|
||||
try {
|
||||
const user = await requirePipelineAdmin();
|
||||
const { packageId } = await params;
|
||||
const result = await markDelivered(packageId, user.id);
|
||||
|
||||
const parsed = recordShareSchema.safeParse(await req.json().catch(() => null));
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: parsed.error.issues[0]?.message ?? "Invalid request", details: parsed.error.issues },
|
||||
{ status: 422 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await markDelivered(packageId, parsed.data, user.id);
|
||||
return NextResponse.json(result);
|
||||
} catch (err) {
|
||||
const { body, status } = toErrorResponse(err);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||
import { requirePipelineAdmin } from "@/lib/render-pipeline/session-auth";
|
||||
import { markUploaded } from "@/lib/render-pipeline/deliveries";
|
||||
import { recordUploadSchema } from "@/lib/render-pipeline/delivery-handoff";
|
||||
|
||||
// ── POST /api/deliveries/{id}/uploaded ───────────────────────────────────────
|
||||
//
|
||||
// The folder is on the client's portal. Records where, so the package shows as
|
||||
// waiting to be shared rather than waiting to be uploaded.
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ packageId: string }> }
|
||||
) {
|
||||
try {
|
||||
const user = await requirePipelineAdmin();
|
||||
const { packageId } = await params;
|
||||
|
||||
const parsed = recordUploadSchema.safeParse(await req.json().catch(() => null));
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: parsed.error.issues[0]?.message ?? "Invalid request", details: parsed.error.issues },
|
||||
{ status: 422 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await markUploaded(packageId, parsed.data, user.id);
|
||||
return NextResponse.json(result);
|
||||
} catch (err) {
|
||||
const { body, status } = toErrorResponse(err);
|
||||
return NextResponse.json(body, { status });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||
import { requirePipelineAdmin } from "@/lib/render-pipeline/session-auth";
|
||||
import { cancelDeliveryRequest } from "@/lib/render-pipeline/delivery-requests";
|
||||
import { cancelRequestSchema } from "@/lib/render-pipeline/delivery-request-state";
|
||||
|
||||
// ── POST /api/delivery-requests/{id}/cancel ──────────────────────────────────
|
||||
//
|
||||
// The only way a request leaves the awaiting list without being delivered, and
|
||||
// it has to say why.
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ requestId: string }> }
|
||||
) {
|
||||
try {
|
||||
const user = await requirePipelineAdmin();
|
||||
const { requestId } = await params;
|
||||
|
||||
const parsed = cancelRequestSchema.safeParse(await req.json().catch(() => null));
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: parsed.error.issues[0]?.message ?? "Invalid request", details: parsed.error.issues },
|
||||
{ status: 422 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await cancelDeliveryRequest(requestId, parsed.data.reason, user.id);
|
||||
return NextResponse.json(result);
|
||||
} catch (err) {
|
||||
const { body, status } = toErrorResponse(err);
|
||||
return NextResponse.json(body, { status });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||
import { requirePipelineUser } from "@/lib/render-pipeline/session-auth";
|
||||
import { getRequestOptions } from "@/lib/render-pipeline/delivery-requests";
|
||||
|
||||
// ── GET /api/delivery-requests/options?projectId= ────────────────────────────
|
||||
//
|
||||
// The episodes a request can be logged against.
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
await requirePipelineUser();
|
||||
const projectId = new URL(req.url).searchParams.get("projectId");
|
||||
if (!projectId) {
|
||||
return NextResponse.json({ error: "projectId is required" }, { status: 400 });
|
||||
}
|
||||
return NextResponse.json(await getRequestOptions(projectId));
|
||||
} catch (err) {
|
||||
const { body, status } = toErrorResponse(err);
|
||||
return NextResponse.json(body, { status });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { toErrorResponse } from "@/lib/render-pipeline/errors";
|
||||
import { requirePipelineAdmin, requirePipelineUser } from "@/lib/render-pipeline/session-auth";
|
||||
import { createDeliveryRequest, listDeliveryRequests } from "@/lib/render-pipeline/delivery-requests";
|
||||
import { createRequestSchema } from "@/lib/render-pipeline/delivery-request-state";
|
||||
|
||||
// ── GET /api/delivery-requests · POST /api/delivery-requests ─────────────────
|
||||
//
|
||||
// What clients have asked for, and how much of each ask has gone out.
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
await requirePipelineUser();
|
||||
const { searchParams } = new URL(req.url);
|
||||
const requests = await listDeliveryRequests({
|
||||
projectId: searchParams.get("projectId") ?? undefined,
|
||||
openOnly: searchParams.get("open") === "1",
|
||||
});
|
||||
return NextResponse.json({ requests });
|
||||
} catch (err) {
|
||||
const { body, status } = toErrorResponse(err);
|
||||
return NextResponse.json(body, { status });
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const user = await requirePipelineAdmin();
|
||||
|
||||
const parsed = createRequestSchema.safeParse(await req.json().catch(() => null));
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: parsed.error.issues[0]?.message ?? "Invalid request", details: parsed.error.issues },
|
||||
{ status: 422 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await createDeliveryRequest(parsed.data, user.id);
|
||||
return NextResponse.json(result, { status: 201 });
|
||||
} catch (err) {
|
||||
const { body, status } = toErrorResponse(err);
|
||||
return NextResponse.json(body, { status });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user