refactor(api): extract timeline project read builders
This commit is contained in:
@@ -7,8 +7,11 @@ import { getAnonymizationDirectory } from "../lib/anonymization.js";
|
||||
import { controllerProcedure } from "../trpc.js";
|
||||
import { loadProjectPlanningReadModel } from "./project-planning-read-model.js";
|
||||
import {
|
||||
buildTimelineProjectContextDetailResponse,
|
||||
buildTimelineProjectContextResponse,
|
||||
buildTimelineProjectAssignmentConflicts,
|
||||
buildTimelineProjectContextSummary,
|
||||
buildTimelineShiftPreviewDetailResponse,
|
||||
resolveTimelineProjectContextPeriod,
|
||||
} from "./timeline-project-context-support.js";
|
||||
import { buildTimelineShiftPlan } from "./timeline-shift-planning.js";
|
||||
@@ -148,20 +151,15 @@ export const timelineProjectReadProcedures = {
|
||||
} = await loadTimelineProjectContext(ctx.db, input.projectId);
|
||||
const directory = await getAnonymizationDirectory(ctx.db);
|
||||
|
||||
return {
|
||||
return buildTimelineProjectContextResponse({
|
||||
project,
|
||||
allocations: allocations.map((allocation) =>
|
||||
anonymizeResourceOnEntry(allocation, directory),
|
||||
),
|
||||
allocations,
|
||||
demands,
|
||||
assignments: assignments.map((assignment) =>
|
||||
anonymizeResourceOnEntry(assignment, directory),
|
||||
),
|
||||
allResourceAllocations: allResourceAllocations.map((allocation) =>
|
||||
anonymizeResourceOnEntry(allocation, directory),
|
||||
),
|
||||
assignments,
|
||||
allResourceAllocations,
|
||||
resourceIds,
|
||||
};
|
||||
directory,
|
||||
});
|
||||
}),
|
||||
|
||||
getProjectContextDetail: controllerProcedure
|
||||
@@ -201,35 +199,18 @@ export const timelineProjectReadProcedures = {
|
||||
allResourceAllocations: projectContext.allResourceAllocations,
|
||||
});
|
||||
|
||||
return {
|
||||
return buildTimelineProjectContextDetailResponse({
|
||||
project: projectContext.project,
|
||||
period: {
|
||||
startDate: fmtDate(period.startDate),
|
||||
endDate: fmtDate(period.endDate),
|
||||
},
|
||||
summary: buildTimelineProjectContextSummary({
|
||||
allocations: projectContext.allocations,
|
||||
demands: projectContext.demands,
|
||||
assignments: projectContext.assignments,
|
||||
resourceIds: projectContext.resourceIds,
|
||||
allResourceAllocations: projectContext.allResourceAllocations,
|
||||
assignmentConflicts,
|
||||
holidayOverlays: formattedHolidayOverlays,
|
||||
}),
|
||||
allocations: projectContext.allocations.map((allocation) =>
|
||||
anonymizeResourceOnEntry(allocation, directory),
|
||||
),
|
||||
period,
|
||||
allocations: projectContext.allocations,
|
||||
demands: projectContext.demands,
|
||||
assignments: projectContext.assignments.map((assignment) =>
|
||||
anonymizeResourceOnEntry(assignment, directory),
|
||||
),
|
||||
allResourceAllocations: projectContext.allResourceAllocations.map((allocation) =>
|
||||
anonymizeResourceOnEntry(allocation, directory),
|
||||
),
|
||||
assignments: projectContext.assignments,
|
||||
allResourceAllocations: projectContext.allResourceAllocations,
|
||||
resourceIds: projectContext.resourceIds,
|
||||
assignmentConflicts,
|
||||
holidayOverlays: formattedHolidayOverlays,
|
||||
resourceIds: projectContext.resourceIds,
|
||||
};
|
||||
directory,
|
||||
});
|
||||
}),
|
||||
|
||||
previewShift: controllerProcedure
|
||||
@@ -258,22 +239,14 @@ export const timelineProjectReadProcedures = {
|
||||
previewTimelineProjectShift(ctx.db, input),
|
||||
]);
|
||||
|
||||
return {
|
||||
project: {
|
||||
id: project.id,
|
||||
name: project.name,
|
||||
shortCode: project.shortCode,
|
||||
status: project.status,
|
||||
responsiblePerson: project.responsiblePerson,
|
||||
startDate: fmtDate(project.startDate),
|
||||
endDate: fmtDate(project.endDate),
|
||||
},
|
||||
return buildTimelineShiftPreviewDetailResponse({
|
||||
project,
|
||||
requestedShift: {
|
||||
newStartDate: fmtDate(input.newStartDate),
|
||||
newEndDate: fmtDate(input.newEndDate),
|
||||
newStartDate: input.newStartDate,
|
||||
newEndDate: input.newEndDate,
|
||||
},
|
||||
preview,
|
||||
};
|
||||
});
|
||||
}),
|
||||
|
||||
getBudgetStatus: controllerProcedure
|
||||
|
||||
Reference in New Issue
Block a user