refactor(api): extract timeline project budget mapping
This commit is contained in:
@@ -7,21 +7,18 @@ import { getAnonymizationDirectory } from "../lib/anonymization.js";
|
||||
import { controllerProcedure } from "../trpc.js";
|
||||
import { loadProjectPlanningReadModel } from "./project-planning-read-model.js";
|
||||
import {
|
||||
buildTimelineBudgetStatusAllocations,
|
||||
buildTimelineBudgetStatusResponse,
|
||||
buildTimelineProjectContextDetailResponse,
|
||||
buildTimelineProjectContextResponse,
|
||||
buildTimelineProjectAssignmentConflicts,
|
||||
buildTimelineProjectContextSummary,
|
||||
buildTimelineShiftValidationBookings,
|
||||
buildTimelineShiftPreviewDetailResponse,
|
||||
resolveTimelineProjectContextPeriod,
|
||||
} from "./timeline-project-context-support.js";
|
||||
import { buildTimelineShiftPlan } from "./timeline-shift-planning.js";
|
||||
import { loadTimelineHolidayOverlays, formatHolidayOverlays } from "./timeline-holiday-read.js";
|
||||
import {
|
||||
anonymizeResourceOnEntry,
|
||||
fmtDate,
|
||||
getAssignmentResourceIds,
|
||||
ShiftDbClient,
|
||||
} from "./timeline-read-shared.js";
|
||||
import { getAssignmentResourceIds, ShiftDbClient } from "./timeline-read-shared.js";
|
||||
import { buildTimelineProjectShiftValidation } from "./timeline-shift-support.js";
|
||||
|
||||
export async function loadProjectShiftContext(db: ShiftDbClient, projectId: string) {
|
||||
@@ -48,19 +45,11 @@ export async function loadProjectShiftContext(db: ShiftDbClient, projectId: stri
|
||||
const allAssignmentWindows =
|
||||
resourceIds.length === 0
|
||||
? []
|
||||
: (
|
||||
: buildTimelineShiftValidationBookings(
|
||||
await listAssignmentBookings(db, {
|
||||
resourceIds,
|
||||
})
|
||||
).map((booking) => ({
|
||||
id: booking.id,
|
||||
resourceId: booking.resourceId!,
|
||||
projectId: booking.projectId,
|
||||
startDate: booking.startDate,
|
||||
endDate: booking.endDate,
|
||||
hoursPerDay: booking.hoursPerDay,
|
||||
status: booking.status,
|
||||
}));
|
||||
}),
|
||||
);
|
||||
|
||||
const shiftPlan = buildTimelineShiftPlan({
|
||||
demandRequirements,
|
||||
@@ -275,26 +264,15 @@ export const timelineProjectReadProcedures = {
|
||||
const budgetStatus = computeBudgetStatus(
|
||||
project.budgetCents,
|
||||
project.winProbability,
|
||||
bookings.map((booking) => ({
|
||||
status: booking.status,
|
||||
dailyCostCents: booking.dailyCostCents,
|
||||
startDate: booking.startDate,
|
||||
endDate: booking.endDate,
|
||||
hoursPerDay: booking.hoursPerDay,
|
||||
})) as unknown as Pick<
|
||||
import("@capakraken/shared").Allocation,
|
||||
"status" | "dailyCostCents" | "startDate" | "endDate" | "hoursPerDay"
|
||||
>[],
|
||||
buildTimelineBudgetStatusAllocations(bookings),
|
||||
project.startDate,
|
||||
project.endDate,
|
||||
);
|
||||
|
||||
return {
|
||||
...budgetStatus,
|
||||
projectName: project.name,
|
||||
projectCode: project.shortCode,
|
||||
return buildTimelineBudgetStatusResponse({
|
||||
project,
|
||||
budgetStatus,
|
||||
totalAllocations: bookings.length,
|
||||
budgetCents: project.budgetCents,
|
||||
};
|
||||
});
|
||||
}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user