refactor(api): extract timeline batch shift support
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { Prisma } from "@capakraken/db";
|
||||
|
||||
export type TimelineBatchShiftMode = "move" | "resize-start" | "resize-end";
|
||||
|
||||
export function shiftTimelineAllocationWindow(input: {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
daysDelta: number;
|
||||
mode: TimelineBatchShiftMode;
|
||||
}): { startDate: Date; endDate: Date } {
|
||||
const startDate = new Date(input.startDate);
|
||||
const endDate = new Date(input.endDate);
|
||||
|
||||
if (input.mode === "move") {
|
||||
startDate.setDate(startDate.getDate() + input.daysDelta);
|
||||
endDate.setDate(endDate.getDate() + input.daysDelta);
|
||||
return { startDate, endDate };
|
||||
}
|
||||
|
||||
if (input.mode === "resize-start") {
|
||||
startDate.setDate(startDate.getDate() + input.daysDelta);
|
||||
if (startDate > endDate) {
|
||||
startDate.setTime(endDate.getTime());
|
||||
}
|
||||
return { startDate, endDate };
|
||||
}
|
||||
|
||||
endDate.setDate(endDate.getDate() + input.daysDelta);
|
||||
if (endDate < startDate) {
|
||||
endDate.setTime(startDate.getTime());
|
||||
}
|
||||
|
||||
return { startDate, endDate };
|
||||
}
|
||||
|
||||
export function buildTimelineBatchShiftAuditChanges(input: {
|
||||
mode: TimelineBatchShiftMode;
|
||||
daysDelta: number;
|
||||
count: number;
|
||||
}): Prisma.InputJsonValue {
|
||||
return {
|
||||
operation: "batchShift",
|
||||
mode: input.mode,
|
||||
daysDelta: input.daysDelta,
|
||||
count: input.count,
|
||||
} as unknown as Prisma.InputJsonValue;
|
||||
}
|
||||
Reference in New Issue
Block a user