chore(repo): initialize planarchy workspace

This commit is contained in:
2026-03-14 14:31:09 +01:00
commit dd55d0e78b
769 changed files with 166461 additions and 0 deletions
@@ -0,0 +1,92 @@
import { buildSplitAllocationReadModel } from "@planarchy/application";
import type { PrismaClient } from "@planarchy/db";
import { AllocationStatus } from "@planarchy/shared";
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,
budgetCents: true,
winProbability: true,
status: true,
startDate: true,
endDate: true,
staffingReqs: true,
responsiblePerson: true,
},
},
roleEntity: {
select: { id: true, name: true, color: true },
},
} 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;
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,
}),
};
}