e7b74f13bd
- Extract shared render helpers (vacation blocks, range overlay, overbooking blink) into renderHelpers.tsx - Centralize status badge styles and vacation color maps into status-styles.ts - Extract dragMath.ts utility from useTimelineDrag for reuse - Split useInvalidatePlanningViews into useInvalidateTimeline (4 queries) + useInvalidatePlanningViews (8 queries) - Adopt findUniqueOrThrow() and Prisma select constants across API routers - Add shared fmtEur() helper for API-side money formatting - Wrap TimelineResourcePanel and TimelineProjectPanel with React.memo - Fix pre-existing TS2589 deep type errors in TeamCalendar and VacationModal - 38 files changed, reducing ~400 lines of duplicated code Co-Authored-By: claude-flow <ruv@ruv.net>
116 lines
2.9 KiB
TypeScript
116 lines
2.9 KiB
TypeScript
import { buildSplitAllocationReadModel } from "@planarchy/application";
|
|
import type { PrismaClient } from "@planarchy/db";
|
|
import { AllocationStatus } from "@planarchy/shared";
|
|
import { ROLE_BRIEF_SELECT } from "../db/selects.js";
|
|
|
|
export const PROJECT_PLANNING_ALLOCATION_INCLUDE = {
|
|
resource: {
|
|
select: {
|
|
id: true,
|
|
displayName: true,
|
|
eid: true,
|
|
chapter: true,
|
|
lcrCents: true,
|
|
availability: true,
|
|
},
|
|
},
|
|
project: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
shortCode: true,
|
|
orderType: true,
|
|
clientId: true,
|
|
budgetCents: true,
|
|
winProbability: true,
|
|
status: true,
|
|
startDate: true,
|
|
endDate: true,
|
|
staffingReqs: true,
|
|
responsiblePerson: true,
|
|
color: true,
|
|
},
|
|
},
|
|
roleEntity: {
|
|
select: ROLE_BRIEF_SELECT,
|
|
},
|
|
} as const;
|
|
|
|
export const PROJECT_PLANNING_DEMAND_INCLUDE = {
|
|
project: PROJECT_PLANNING_ALLOCATION_INCLUDE.project,
|
|
roleEntity: PROJECT_PLANNING_ALLOCATION_INCLUDE.roleEntity,
|
|
} as const;
|
|
|
|
export const PROJECT_PLANNING_ASSIGNMENT_INCLUDE = {
|
|
resource: PROJECT_PLANNING_ALLOCATION_INCLUDE.resource,
|
|
project: PROJECT_PLANNING_ALLOCATION_INCLUDE.project,
|
|
roleEntity: PROJECT_PLANNING_ALLOCATION_INCLUDE.roleEntity,
|
|
} as const;
|
|
|
|
/**
|
|
* Lighter resource select for timeline rendering (hot path).
|
|
* Omits `availability` which is only needed for budget/cost calculations.
|
|
*/
|
|
const TIMELINE_RESOURCE_SELECT = {
|
|
select: {
|
|
id: true,
|
|
displayName: true,
|
|
eid: true,
|
|
chapter: true,
|
|
lcrCents: true,
|
|
},
|
|
} as const;
|
|
|
|
export const TIMELINE_ASSIGNMENT_INCLUDE = {
|
|
resource: TIMELINE_RESOURCE_SELECT,
|
|
project: PROJECT_PLANNING_ALLOCATION_INCLUDE.project,
|
|
roleEntity: PROJECT_PLANNING_ALLOCATION_INCLUDE.roleEntity,
|
|
} as const;
|
|
|
|
type ProjectPlanningReadDbClient = Pick<
|
|
PrismaClient,
|
|
"demandRequirement" | "assignment"
|
|
>;
|
|
|
|
export interface LoadProjectPlanningReadModelInput {
|
|
projectId: string;
|
|
activeOnly?: boolean;
|
|
}
|
|
|
|
export async function loadProjectPlanningReadModel(
|
|
db: ProjectPlanningReadDbClient,
|
|
input: LoadProjectPlanningReadModelInput,
|
|
) {
|
|
const statusFilter = input.activeOnly
|
|
? { status: { not: AllocationStatus.CANCELLED } }
|
|
: {};
|
|
|
|
const [demandRequirements, assignments] = await Promise.all([
|
|
db.demandRequirement.findMany({
|
|
where: {
|
|
projectId: input.projectId,
|
|
...statusFilter,
|
|
},
|
|
include: PROJECT_PLANNING_DEMAND_INCLUDE,
|
|
orderBy: [{ startDate: "asc" }, { projectId: "asc" }],
|
|
}),
|
|
db.assignment.findMany({
|
|
where: {
|
|
projectId: input.projectId,
|
|
...statusFilter,
|
|
},
|
|
include: PROJECT_PLANNING_ASSIGNMENT_INCLUDE,
|
|
orderBy: [{ startDate: "asc" }, { resourceId: "asc" }],
|
|
}),
|
|
]);
|
|
|
|
return {
|
|
demandRequirements,
|
|
assignments,
|
|
readModel: buildSplitAllocationReadModel({
|
|
demandRequirements,
|
|
assignments,
|
|
}),
|
|
};
|
|
}
|