refactor(api): extract timeline project query and read helpers

This commit is contained in:
2026-03-31 16:01:35 +02:00
parent fda6bcab74
commit 803de725ad
7 changed files with 357 additions and 288 deletions
@@ -0,0 +1,60 @@
import type { Prisma } from "@capakraken/db";
import { findUniqueOrThrow } from "../db/helpers.js";
import type { ShiftDbClient } from "./timeline-read-shared.js";
export const projectShiftContextSelect = {
id: true,
budgetCents: true,
winProbability: true,
startDate: true,
endDate: true,
} as const satisfies Prisma.ProjectSelect;
export const timelineProjectContextSelect = {
id: true,
name: true,
shortCode: true,
orderType: true,
budgetCents: true,
winProbability: true,
status: true,
startDate: true,
endDate: true,
staffingReqs: true,
} as const satisfies Prisma.ProjectSelect;
export const timelineShiftPreviewProjectSelect = {
id: true,
name: true,
shortCode: true,
status: true,
responsiblePerson: true,
startDate: true,
endDate: true,
} as const satisfies Prisma.ProjectSelect;
export const timelineBudgetStatusProjectSelect = {
id: true,
name: true,
shortCode: true,
budgetCents: true,
winProbability: true,
startDate: true,
endDate: true,
} as const satisfies Prisma.ProjectSelect;
export async function findTimelineProjectOrThrow<TSelect extends Prisma.ProjectSelect>(
db: Pick<ShiftDbClient, "project">,
input: {
projectId: string;
select: TSelect;
},
): Promise<Prisma.ProjectGetPayload<{ select: TSelect }>> {
return findUniqueOrThrow(
db.project.findUnique({
where: { id: input.projectId },
select: input.select,
}),
"Project",
) as Promise<Prisma.ProjectGetPayload<{ select: TSelect }>>;
}