refactor(api): extract timeline allocation mutation payload helpers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Prisma } from "@capakraken/db";
|
||||
import { AllocationStatus } from "@capakraken/shared";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
export type TimelineBatchShiftMode = "move" | "resize-start" | "resize-end";
|
||||
@@ -39,6 +40,39 @@ export function buildTimelineQuickAssignMetadata(source: "quickAssign" | "batchQ
|
||||
return { source } satisfies Record<string, unknown>;
|
||||
}
|
||||
|
||||
export function buildTimelineQuickAssignAssignmentInput(input: {
|
||||
resourceId: string;
|
||||
projectId: string;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
hoursPerDay: number;
|
||||
role: string;
|
||||
roleId?: string | undefined;
|
||||
status: AllocationStatus;
|
||||
source: "quickAssign" | "batchQuickAssign";
|
||||
}) {
|
||||
return {
|
||||
resourceId: input.resourceId,
|
||||
projectId: input.projectId,
|
||||
startDate: input.startDate,
|
||||
endDate: input.endDate,
|
||||
hoursPerDay: input.hoursPerDay,
|
||||
percentage: calculateTimelineAllocationPercentage(input.hoursPerDay),
|
||||
role: input.role,
|
||||
...(input.roleId !== undefined ? { roleId: input.roleId } : {}),
|
||||
status: input.status,
|
||||
metadata: buildTimelineQuickAssignMetadata(input.source),
|
||||
};
|
||||
}
|
||||
|
||||
export function validateTimelineAllocationDateRanges(
|
||||
ranges: Array<{ startDate: Date; endDate: Date }>,
|
||||
): void {
|
||||
for (const range of ranges) {
|
||||
assertTimelineDateRangeValid(range.startDate, range.endDate);
|
||||
}
|
||||
}
|
||||
|
||||
export function shiftTimelineAllocationWindow(input: {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
@@ -98,6 +132,33 @@ export function buildTimelineAllocationUpdateAuditChanges(input: {
|
||||
} as unknown as Prisma.InputJsonValue;
|
||||
}
|
||||
|
||||
export function buildTimelineAllocationEntryUpdate(input: {
|
||||
hoursPerDay: number;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
metadata: Record<string, unknown>;
|
||||
dailyCostCents: number;
|
||||
role?: string | undefined;
|
||||
}) {
|
||||
return {
|
||||
demandRequirementUpdate: {
|
||||
hoursPerDay: input.hoursPerDay,
|
||||
startDate: input.startDate,
|
||||
endDate: input.endDate,
|
||||
metadata: input.metadata,
|
||||
...(input.role !== undefined ? { role: input.role } : {}),
|
||||
},
|
||||
assignmentUpdate: {
|
||||
hoursPerDay: input.hoursPerDay,
|
||||
startDate: input.startDate,
|
||||
endDate: input.endDate,
|
||||
dailyCostCents: input.dailyCostCents,
|
||||
metadata: input.metadata,
|
||||
...(input.role !== undefined ? { role: input.role } : {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function buildTimelineBatchShiftAuditChanges(input: {
|
||||
mode: TimelineBatchShiftMode;
|
||||
daysDelta: number;
|
||||
|
||||
Reference in New Issue
Block a user