refactor(api): align timeline project read routing
This commit is contained in:
@@ -41,6 +41,7 @@ import {
|
|||||||
} from "../router/timeline-project-query-support.js";
|
} from "../router/timeline-project-query-support.js";
|
||||||
import {
|
import {
|
||||||
readTimelineProjectBudgetStatusResponse,
|
readTimelineProjectBudgetStatusResponse,
|
||||||
|
readTimelineProjectShiftPreview,
|
||||||
readTimelineProjectShiftPreviewDetail,
|
readTimelineProjectShiftPreviewDetail,
|
||||||
} from "../router/timeline-project-procedure-support.js";
|
} from "../router/timeline-project-procedure-support.js";
|
||||||
|
|
||||||
@@ -89,6 +90,24 @@ describe("timeline project procedure support", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("loads plain shift preview responses through procedure support", async () => {
|
||||||
|
previewTimelineProjectShiftMock.mockResolvedValueOnce({ valid: true } as never);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
readTimelineProjectShiftPreview({} as never, {
|
||||||
|
projectId: "project_1",
|
||||||
|
newStartDate: new Date("2026-04-03T00:00:00.000Z"),
|
||||||
|
newEndDate: new Date("2026-04-12T00:00:00.000Z"),
|
||||||
|
}),
|
||||||
|
).resolves.toEqual({ valid: true });
|
||||||
|
|
||||||
|
expect(previewTimelineProjectShiftMock).toHaveBeenCalledWith({}, {
|
||||||
|
projectId: "project_1",
|
||||||
|
newStartDate: new Date("2026-04-03T00:00:00.000Z"),
|
||||||
|
newEndDate: new Date("2026-04-12T00:00:00.000Z"),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("builds budget status responses from project bookings", async () => {
|
it("builds budget status responses from project bookings", async () => {
|
||||||
findTimelineProjectOrThrowMock.mockResolvedValueOnce({
|
findTimelineProjectOrThrowMock.mockResolvedValueOnce({
|
||||||
id: "project_1",
|
id: "project_1",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
buildTimelineEntriesDetailInput,
|
buildTimelineEntriesDetailInput,
|
||||||
TimelineDetailFiltersSchema,
|
TimelineDetailFiltersSchema,
|
||||||
TimelineProjectContextDetailSchema,
|
TimelineProjectContextDetailSchema,
|
||||||
|
TimelineProjectIdSchema,
|
||||||
} from "../router/timeline-read-shared.js";
|
} from "../router/timeline-read-shared.js";
|
||||||
|
|
||||||
describe("timeline read shared", () => {
|
describe("timeline read shared", () => {
|
||||||
@@ -68,5 +69,11 @@ describe("timeline read shared", () => {
|
|||||||
endDate: "2026-04-20",
|
endDate: "2026-04-20",
|
||||||
durationDays: undefined,
|
durationDays: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(TimelineProjectIdSchema.parse({
|
||||||
|
projectId: "project_1",
|
||||||
|
})).toEqual({
|
||||||
|
projectId: "project_1",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -45,6 +45,17 @@ export async function readTimelineProjectShiftPreviewDetail(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function readTimelineProjectShiftPreview(
|
||||||
|
db: TimelineProjectProcedureDb,
|
||||||
|
input: {
|
||||||
|
projectId: string;
|
||||||
|
newStartDate: Date;
|
||||||
|
newEndDate: Date;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
return previewTimelineProjectShift(db, input);
|
||||||
|
}
|
||||||
|
|
||||||
export async function readTimelineProjectBudgetStatusResponse(
|
export async function readTimelineProjectBudgetStatusResponse(
|
||||||
db: TimelineProjectProcedureDb,
|
db: TimelineProjectProcedureDb,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { ShiftProjectSchema } from "@capakraken/shared";
|
import { ShiftProjectSchema } from "@capakraken/shared";
|
||||||
import { z } from "zod";
|
|
||||||
import { controllerProcedure } from "../trpc.js";
|
import { controllerProcedure } from "../trpc.js";
|
||||||
import { previewTimelineProjectShift } from "./timeline-project-load-support.js";
|
|
||||||
import {
|
import {
|
||||||
TimelineProjectContextDetailSchema,
|
TimelineProjectContextDetailSchema,
|
||||||
|
TimelineProjectIdSchema,
|
||||||
} from "./timeline-read-shared.js";
|
} from "./timeline-read-shared.js";
|
||||||
import {
|
import {
|
||||||
readTimelineProjectContextDetailResponse,
|
readTimelineProjectContextDetailResponse,
|
||||||
@@ -11,12 +10,13 @@ import {
|
|||||||
} from "./timeline-project-context-procedure-support.js";
|
} from "./timeline-project-context-procedure-support.js";
|
||||||
import {
|
import {
|
||||||
readTimelineProjectBudgetStatusResponse,
|
readTimelineProjectBudgetStatusResponse,
|
||||||
|
readTimelineProjectShiftPreview,
|
||||||
readTimelineProjectShiftPreviewDetail,
|
readTimelineProjectShiftPreviewDetail,
|
||||||
} from "./timeline-project-procedure-support.js";
|
} from "./timeline-project-procedure-support.js";
|
||||||
|
|
||||||
export const timelineProjectReadProcedures = {
|
export const timelineProjectReadProcedures = {
|
||||||
getProjectContext: controllerProcedure
|
getProjectContext: controllerProcedure
|
||||||
.input(z.object({ projectId: z.string() }))
|
.input(TimelineProjectIdSchema)
|
||||||
.query(async ({ ctx, input }) => readTimelineProjectContextResponse(ctx.db, input.projectId)),
|
.query(async ({ ctx, input }) => readTimelineProjectContextResponse(ctx.db, input.projectId)),
|
||||||
|
|
||||||
getProjectContextDetail: controllerProcedure
|
getProjectContextDetail: controllerProcedure
|
||||||
@@ -25,13 +25,13 @@ export const timelineProjectReadProcedures = {
|
|||||||
|
|
||||||
previewShift: controllerProcedure
|
previewShift: controllerProcedure
|
||||||
.input(ShiftProjectSchema)
|
.input(ShiftProjectSchema)
|
||||||
.query(async ({ ctx, input }) => previewTimelineProjectShift(ctx.db, input)),
|
.query(async ({ ctx, input }) => readTimelineProjectShiftPreview(ctx.db, input)),
|
||||||
|
|
||||||
getShiftPreviewDetail: controllerProcedure
|
getShiftPreviewDetail: controllerProcedure
|
||||||
.input(ShiftProjectSchema)
|
.input(ShiftProjectSchema)
|
||||||
.query(async ({ ctx, input }) => readTimelineProjectShiftPreviewDetail(ctx.db, input)),
|
.query(async ({ ctx, input }) => readTimelineProjectShiftPreviewDetail(ctx.db, input)),
|
||||||
|
|
||||||
getBudgetStatus: controllerProcedure
|
getBudgetStatus: controllerProcedure
|
||||||
.input(z.object({ projectId: z.string() }))
|
.input(TimelineProjectIdSchema)
|
||||||
.query(async ({ ctx, input }) => readTimelineProjectBudgetStatusResponse(ctx.db, input.projectId)),
|
.query(async ({ ctx, input }) => readTimelineProjectBudgetStatusResponse(ctx.db, input.projectId)),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ export const TimelineProjectContextDetailSchema = z.object({
|
|||||||
durationDays: z.number().int().min(1).max(366).optional(),
|
durationDays: z.number().int().min(1).max(366).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const TimelineProjectIdSchema = z.object({
|
||||||
|
projectId: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
type TimelineWindowFiltersInput = z.infer<typeof TimelineWindowFiltersSchema>;
|
type TimelineWindowFiltersInput = z.infer<typeof TimelineWindowFiltersSchema>;
|
||||||
|
|
||||||
export function getAssignmentResourceIds(
|
export function getAssignmentResourceIds(
|
||||||
|
|||||||
Reference in New Issue
Block a user