@@ -2,6 +2,13 @@ import { z } from "zod";
|
||||
import { db } from "@/lib/db";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
function isPrismaTableOrColumnMissingError(error: unknown): boolean {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
return error.code === "P2021" || error.code === "P2022";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const exportManifestSchema = z.object({
|
||||
shotCode: z.string().min(1),
|
||||
projectCode: z.string().min(1),
|
||||
@@ -152,23 +159,40 @@ export async function createRenderExport(input: {
|
||||
}
|
||||
|
||||
export async function listExportsForQueue() {
|
||||
return db.export.findMany({
|
||||
where: { status: { notIn: ["SUPERSEDED", "ARCHIVED", "CANCELLED", "DELIVERED"] } },
|
||||
orderBy: [{ createdAt: "desc" }],
|
||||
include: {
|
||||
shot: { select: { shotCode: true, shotVersion: true, project: { select: { code: true } } } },
|
||||
renderJobs: { orderBy: [{ createdAt: "desc" }], take: 1 },
|
||||
},
|
||||
});
|
||||
try {
|
||||
return await db.export.findMany({
|
||||
where: { status: { notIn: ["SUPERSEDED", "ARCHIVED", "CANCELLED", "DELIVERED"] } },
|
||||
orderBy: [{ createdAt: "desc" }],
|
||||
include: {
|
||||
shot: { select: { shotCode: true, shotVersion: true, project: { select: { code: true } } } },
|
||||
renderJobs: { orderBy: [{ createdAt: "desc" }], take: 1 },
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
// Render pipeline tables may not exist yet if Phase 1 migrations have not been applied.
|
||||
if (isPrismaTableOrColumnMissingError(error)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getLatestExportForShot(shotId: string) {
|
||||
return db.export.findFirst({
|
||||
where: { shotId },
|
||||
orderBy: [{ createdAt: "desc" }],
|
||||
include: {
|
||||
shot: { select: { shotCode: true, project: { select: { code: true } } } },
|
||||
renderJobs: { orderBy: [{ createdAt: "desc" }], take: 1 },
|
||||
},
|
||||
});
|
||||
try {
|
||||
return await db.export.findFirst({
|
||||
where: { shotId },
|
||||
orderBy: [{ createdAt: "desc" }],
|
||||
include: {
|
||||
shot: { select: { shotCode: true, project: { select: { code: true } } } },
|
||||
renderJobs: { orderBy: [{ createdAt: "desc" }], take: 1 },
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
if (isPrismaTableOrColumnMissingError(error)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user