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:
@@ -5,6 +5,7 @@ import { PipelineError } from "./errors";
|
||||
import { applyTransition } from "./transitions";
|
||||
import { getConfigNumber, getConfigValue } from "./config";
|
||||
import { clientShotCode } from "@/lib/shot-code";
|
||||
import type { RecordShareInput, RecordUploadInput } from "./delivery-handoff";
|
||||
|
||||
/**
|
||||
* Delivery builder (RenderPipeline2 §11). The web app decides *what* goes in a
|
||||
@@ -640,11 +641,33 @@ export async function listDeliveryPackages(filter: {
|
||||
},
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: {
|
||||
items: { select: { id: true, shotCode: true, versionString: true, status: true, fileCount: true, linkMode: true, errorMessage: true } },
|
||||
items: {
|
||||
select: {
|
||||
id: true,
|
||||
shotCode: true,
|
||||
clientCode: true,
|
||||
versionString: true,
|
||||
status: true,
|
||||
fileCount: true,
|
||||
totalBytes: true,
|
||||
movPath: true,
|
||||
linkMode: true,
|
||||
errorMessage: true,
|
||||
},
|
||||
},
|
||||
project: { select: { id: true, name: true, code: true } },
|
||||
},
|
||||
});
|
||||
|
||||
// Who recorded each handoff step — the ids are plain columns, not relations.
|
||||
const userIds = [
|
||||
...new Set(packages.flatMap((p) => [p.uploadedById, p.deliveredById]).filter((id): id is string => !!id)),
|
||||
];
|
||||
const users = userIds.length
|
||||
? await db.user.findMany({ where: { id: { in: userIds } }, select: { id: true, name: true, email: true } })
|
||||
: [];
|
||||
const userName = new Map(users.map((u) => [u.id, u.name ?? u.email]));
|
||||
|
||||
return {
|
||||
packages: packages.map((p) => ({
|
||||
id: p.id,
|
||||
@@ -659,30 +682,71 @@ export async function listDeliveryPackages(filter: {
|
||||
projectCode: p.project.code,
|
||||
createdAt: p.createdAt,
|
||||
builtAt: p.builtAt,
|
||||
uploadUrl: p.uploadUrl,
|
||||
uploadedAt: p.uploadedAt,
|
||||
uploadedByName: p.uploadedById ? (userName.get(p.uploadedById) ?? null) : null,
|
||||
sharedWith: p.sharedWith,
|
||||
sharedNote: p.sharedNote,
|
||||
deliveredAt: p.deliveredAt,
|
||||
deliveredByName: p.deliveredById ? (userName.get(p.deliveredById) ?? null) : null,
|
||||
itemCount: p.items.length,
|
||||
verifiedCount: p.items.filter((i) => i.status === "VERIFIED").length,
|
||||
items: p.items,
|
||||
// What the upload should contain, for the person comparing it against
|
||||
// the client's portal.
|
||||
exrFileCount: p.items.reduce((sum, i) => sum + (i.fileCount ?? 0), 0),
|
||||
movCount: p.items.filter((i) => i.movPath).length,
|
||||
totalBytes: p.items.reduce((sum, i) => sum + Number(i.totalBytes ?? 0), 0),
|
||||
items: p.items.map(({ totalBytes: _bytes, movPath: _mov, ...item }) => item),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
/** E19 — the human uploaded the folder to the client and is confirming it. */
|
||||
export async function markDelivered(packageId: string, userId: string) {
|
||||
function assertHandoffAllowed(pkg: { kind: DeliveryKind; status: DeliveryStatus }, verb: string) {
|
||||
if (pkg.kind !== "EXR_DELIVERY") {
|
||||
throw new PipelineError(
|
||||
409,
|
||||
"A MOV review package is shared for review, not delivered — it has no delivered state"
|
||||
);
|
||||
}
|
||||
if (pkg.status !== "READY") {
|
||||
throw new PipelineError(409, `Package is ${pkg.status} — only a READY package can be ${verb}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Step one of the handoff: the folder is on the client's portal, and this is
|
||||
* where. Repeatable while the package is READY, so a wrong link can be
|
||||
* corrected before it is shared.
|
||||
*/
|
||||
export async function markUploaded(packageId: string, input: RecordUploadInput, userId: string) {
|
||||
return db.$transaction(async (tx) => {
|
||||
const pkg = await tx.deliveryPackage.findUnique({ where: { id: packageId } });
|
||||
if (!pkg) throw new PipelineError(404, "Delivery package not found");
|
||||
assertHandoffAllowed(pkg, "recorded as uploaded");
|
||||
|
||||
const updated = await tx.deliveryPackage.update({
|
||||
where: { id: pkg.id },
|
||||
data: { uploadUrl: input.uploadUrl, uploadedAt: new Date(), uploadedById: userId },
|
||||
});
|
||||
return { package: { id: updated.id, status: updated.status, uploadUrl: updated.uploadUrl } };
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* E19 — step two: the link was sent to a named person, which is what makes the
|
||||
* package DELIVERED. Refused until the upload location is on record, so
|
||||
* "delivered" always has somewhere to point.
|
||||
*/
|
||||
export async function markDelivered(packageId: string, input: RecordShareInput, userId: string) {
|
||||
return db.$transaction(async (tx) => {
|
||||
const pkg = await tx.deliveryPackage.findUnique({ where: { id: packageId }, include: { items: true } });
|
||||
if (!pkg) throw new PipelineError(404, "Delivery package not found");
|
||||
if (pkg.status === "DELIVERED") {
|
||||
return { package: { id: pkg.id, status: pkg.status }, alreadyApplied: true };
|
||||
}
|
||||
if (pkg.status !== "READY") {
|
||||
throw new PipelineError(409, `Package is ${pkg.status} — only a READY package can be marked delivered`);
|
||||
}
|
||||
if (pkg.kind !== "EXR_DELIVERY") {
|
||||
throw new PipelineError(
|
||||
409,
|
||||
"A MOV review package is shared for review, not delivered — it has no delivered state"
|
||||
);
|
||||
assertHandoffAllowed(pkg, "marked delivered");
|
||||
if (!pkg.uploadedAt || !pkg.uploadUrl) {
|
||||
throw new PipelineError(409, "Record where the package was uploaded before marking it delivered");
|
||||
}
|
||||
|
||||
for (const item of pkg.items) {
|
||||
@@ -698,7 +762,13 @@ export async function markDelivered(packageId: string, userId: string) {
|
||||
|
||||
const updated = await tx.deliveryPackage.update({
|
||||
where: { id: pkg.id },
|
||||
data: { status: "DELIVERED", deliveredAt: new Date(), deliveredById: userId },
|
||||
data: {
|
||||
status: "DELIVERED",
|
||||
sharedWith: input.sharedWith,
|
||||
sharedNote: input.note || null,
|
||||
deliveredAt: new Date(),
|
||||
deliveredById: userId,
|
||||
},
|
||||
});
|
||||
return { package: { id: updated.id, status: updated.status }, alreadyApplied: false };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user