refactor(api): extract timeline project query and read helpers
This commit is contained in:
@@ -2,38 +2,37 @@ import { listAssignmentBookings } from "@capakraken/application";
|
||||
import { computeBudgetStatus } from "@capakraken/engine";
|
||||
import { ShiftProjectSchema } from "@capakraken/shared";
|
||||
import { z } from "zod";
|
||||
import { findUniqueOrThrow } from "../db/helpers.js";
|
||||
import { getAnonymizationDirectory } from "../lib/anonymization.js";
|
||||
import { controllerProcedure } from "../trpc.js";
|
||||
import { loadProjectPlanningReadModel } from "./project-planning-read-model.js";
|
||||
import {
|
||||
buildTimelineBudgetStatusAllocations,
|
||||
buildTimelineBudgetStatusResponse,
|
||||
buildTimelineShiftValidationBookings,
|
||||
buildTimelineShiftPreviewDetailResponse,
|
||||
buildTimelineProjectContextDetailResponse,
|
||||
buildTimelineProjectContextResponse,
|
||||
loadTimelineProjectContextDetailArtifacts,
|
||||
} from "./timeline-project-context-support.js";
|
||||
import {
|
||||
buildTimelineBudgetStatusAllocations,
|
||||
buildTimelineBudgetStatusResponse,
|
||||
buildTimelineShiftPreviewDetailResponse,
|
||||
buildTimelineShiftValidationBookings,
|
||||
} from "./timeline-project-read-support.js";
|
||||
import {
|
||||
findTimelineProjectOrThrow,
|
||||
projectShiftContextSelect,
|
||||
timelineBudgetStatusProjectSelect,
|
||||
timelineProjectContextSelect,
|
||||
timelineShiftPreviewProjectSelect,
|
||||
} from "./timeline-project-query-support.js";
|
||||
import { buildTimelineShiftPlan } from "./timeline-shift-planning.js";
|
||||
import { getAssignmentResourceIds, ShiftDbClient } from "./timeline-read-shared.js";
|
||||
import { buildTimelineProjectShiftValidation } from "./timeline-shift-support.js";
|
||||
|
||||
export async function loadProjectShiftContext(db: ShiftDbClient, projectId: string) {
|
||||
const [project, planningRead] = await Promise.all([
|
||||
findUniqueOrThrow(
|
||||
db.project.findUnique({
|
||||
where: { id: projectId },
|
||||
select: {
|
||||
id: true,
|
||||
budgetCents: true,
|
||||
winProbability: true,
|
||||
startDate: true,
|
||||
endDate: true,
|
||||
},
|
||||
}),
|
||||
"Project",
|
||||
),
|
||||
findTimelineProjectOrThrow(db, {
|
||||
projectId,
|
||||
select: projectShiftContextSelect,
|
||||
}),
|
||||
loadProjectPlanningReadModel(db, { projectId, activeOnly: true }),
|
||||
]);
|
||||
|
||||
@@ -65,24 +64,10 @@ export async function loadProjectShiftContext(db: ShiftDbClient, projectId: stri
|
||||
|
||||
export async function loadTimelineProjectContext(db: ShiftDbClient, projectId: string) {
|
||||
const [project, planningRead] = await Promise.all([
|
||||
findUniqueOrThrow(
|
||||
db.project.findUnique({
|
||||
where: { id: projectId },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
shortCode: true,
|
||||
orderType: true,
|
||||
budgetCents: true,
|
||||
winProbability: true,
|
||||
status: true,
|
||||
startDate: true,
|
||||
endDate: true,
|
||||
staffingReqs: true,
|
||||
},
|
||||
}),
|
||||
"Project",
|
||||
),
|
||||
findTimelineProjectOrThrow(db, {
|
||||
projectId,
|
||||
select: timelineProjectContextSelect,
|
||||
}),
|
||||
loadProjectPlanningReadModel(db, {
|
||||
projectId,
|
||||
activeOnly: true,
|
||||
@@ -198,21 +183,10 @@ export const timelineProjectReadProcedures = {
|
||||
.input(ShiftProjectSchema)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const [project, preview] = await Promise.all([
|
||||
findUniqueOrThrow(
|
||||
ctx.db.project.findUnique({
|
||||
where: { id: input.projectId },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
shortCode: true,
|
||||
status: true,
|
||||
responsiblePerson: true,
|
||||
startDate: true,
|
||||
endDate: true,
|
||||
},
|
||||
}),
|
||||
"Project",
|
||||
),
|
||||
findTimelineProjectOrThrow(ctx.db, {
|
||||
projectId: input.projectId,
|
||||
select: timelineShiftPreviewProjectSelect,
|
||||
}),
|
||||
previewTimelineProjectShift(ctx.db, input),
|
||||
]);
|
||||
|
||||
@@ -229,21 +203,10 @@ export const timelineProjectReadProcedures = {
|
||||
getBudgetStatus: controllerProcedure
|
||||
.input(z.object({ projectId: z.string() }))
|
||||
.query(async ({ ctx, input }) => {
|
||||
const project = await findUniqueOrThrow(
|
||||
ctx.db.project.findUnique({
|
||||
where: { id: input.projectId },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
shortCode: true,
|
||||
budgetCents: true,
|
||||
winProbability: true,
|
||||
startDate: true,
|
||||
endDate: true,
|
||||
},
|
||||
}),
|
||||
"Project",
|
||||
);
|
||||
const project = await findTimelineProjectOrThrow(ctx.db, {
|
||||
projectId: input.projectId,
|
||||
select: timelineBudgetStatusProjectSelect,
|
||||
});
|
||||
|
||||
const bookings = await listAssignmentBookings(ctx.db, {
|
||||
projectIds: [project.id],
|
||||
|
||||
Reference in New Issue
Block a user