From d61527b38c173b6231316ae0abef6c81d72efab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Tue, 31 Mar 2026 18:56:01 +0200 Subject: [PATCH] refactor(api): split timeline read schemas --- .../__tests__/timeline-read-shared.test.ts | 4 ++- .../api/src/router/timeline-entry-read.ts | 2 +- .../api/src/router/timeline-holiday-read.ts | 2 +- .../api/src/router/timeline-project-read.ts | 2 +- .../router/timeline-read-schema-support.ts | 35 +++++++++++++++++++ .../api/src/router/timeline-read-shared.ts | 35 +------------------ 6 files changed, 42 insertions(+), 38 deletions(-) create mode 100644 packages/api/src/router/timeline-read-schema-support.ts diff --git a/packages/api/src/__tests__/timeline-read-shared.test.ts b/packages/api/src/__tests__/timeline-read-shared.test.ts index 2346a81..c7422ec 100644 --- a/packages/api/src/__tests__/timeline-read-shared.test.ts +++ b/packages/api/src/__tests__/timeline-read-shared.test.ts @@ -1,10 +1,12 @@ import { describe, expect, it } from "vitest"; import { buildTimelineEntriesDetailInput, +} from "../router/timeline-read-shared.js"; +import { TimelineDetailFiltersSchema, TimelineProjectContextDetailSchema, TimelineProjectIdSchema, -} from "../router/timeline-read-shared.js"; +} from "../router/timeline-read-schema-support.js"; describe("timeline read shared", () => { it("builds detail input from period and normalized filters", () => { diff --git a/packages/api/src/router/timeline-entry-read.ts b/packages/api/src/router/timeline-entry-read.ts index 3367037..5e3afd0 100644 --- a/packages/api/src/router/timeline-entry-read.ts +++ b/packages/api/src/router/timeline-entry-read.ts @@ -2,7 +2,7 @@ import { controllerProcedure, protectedProcedure } from "../trpc.js"; import { TimelineDetailFiltersSchema, TimelineWindowFiltersSchema, -} from "./timeline-read-shared.js"; +} from "./timeline-read-schema-support.js"; import { readMyTimelineEntriesView, readTimelineEntries, diff --git a/packages/api/src/router/timeline-holiday-read.ts b/packages/api/src/router/timeline-holiday-read.ts index 16c6d9d..c91d07c 100644 --- a/packages/api/src/router/timeline-holiday-read.ts +++ b/packages/api/src/router/timeline-holiday-read.ts @@ -2,7 +2,7 @@ import { controllerProcedure, protectedProcedure } from "../trpc.js"; import { TimelineDetailFiltersSchema, TimelineWindowFiltersSchema, -} from "./timeline-read-shared.js"; +} from "./timeline-read-schema-support.js"; import { loadTimelineHolidayOverlays, } from "./timeline-holiday-load-support.js"; diff --git a/packages/api/src/router/timeline-project-read.ts b/packages/api/src/router/timeline-project-read.ts index a4fb489..2722edc 100644 --- a/packages/api/src/router/timeline-project-read.ts +++ b/packages/api/src/router/timeline-project-read.ts @@ -3,7 +3,7 @@ import { controllerProcedure } from "../trpc.js"; import { TimelineProjectContextDetailSchema, TimelineProjectIdSchema, -} from "./timeline-read-shared.js"; +} from "./timeline-read-schema-support.js"; import { readTimelineProjectContextDetailResponse, readTimelineProjectContextResponse, diff --git a/packages/api/src/router/timeline-read-schema-support.ts b/packages/api/src/router/timeline-read-schema-support.ts new file mode 100644 index 0000000..9c29a60 --- /dev/null +++ b/packages/api/src/router/timeline-read-schema-support.ts @@ -0,0 +1,35 @@ +import { z } from "zod"; + +export const TimelineWindowFiltersSchema = z.object({ + startDate: z.coerce.date(), + endDate: z.coerce.date(), + resourceIds: z.array(z.string()).optional(), + projectIds: z.array(z.string()).optional(), + clientIds: z.array(z.string()).optional(), + chapters: z.array(z.string()).optional(), + eids: z.array(z.string()).optional(), + countryCodes: z.array(z.string()).optional(), +}); + +export const TimelineDetailFiltersSchema = z.object({ + startDate: z.string().optional(), + endDate: z.string().optional(), + durationDays: z.number().int().min(1).max(366).optional(), + resourceIds: z.array(z.string()).optional(), + projectIds: z.array(z.string()).optional(), + clientIds: z.array(z.string()).optional(), + chapters: z.array(z.string()).optional(), + eids: z.array(z.string()).optional(), + countryCodes: z.array(z.string()).optional(), +}); + +export const TimelineProjectContextDetailSchema = z.object({ + projectId: z.string(), + startDate: z.string().optional(), + endDate: z.string().optional(), + durationDays: z.number().int().min(1).max(366).optional(), +}); + +export const TimelineProjectIdSchema = z.object({ + projectId: z.string(), +}); diff --git a/packages/api/src/router/timeline-read-shared.ts b/packages/api/src/router/timeline-read-shared.ts index f8ad155..d286795 100644 --- a/packages/api/src/router/timeline-read-shared.ts +++ b/packages/api/src/router/timeline-read-shared.ts @@ -1,6 +1,7 @@ import { buildSplitAllocationReadModel } from "@capakraken/application"; import type { PrismaClient } from "@capakraken/db"; import { z } from "zod"; +import { TimelineWindowFiltersSchema } from "./timeline-read-schema-support.js"; import { loadTimelineEntryRecords } from "./timeline-entry-query-support.js"; export { buildSelfServiceTimelineInput, @@ -30,40 +31,6 @@ export type TimelineEntriesFilters = { countryCodes?: string[] | undefined; }; -export const TimelineWindowFiltersSchema = z.object({ - startDate: z.coerce.date(), - endDate: z.coerce.date(), - resourceIds: z.array(z.string()).optional(), - projectIds: z.array(z.string()).optional(), - clientIds: z.array(z.string()).optional(), - chapters: z.array(z.string()).optional(), - eids: z.array(z.string()).optional(), - countryCodes: z.array(z.string()).optional(), -}); - -export const TimelineDetailFiltersSchema = z.object({ - startDate: z.string().optional(), - endDate: z.string().optional(), - durationDays: z.number().int().min(1).max(366).optional(), - resourceIds: z.array(z.string()).optional(), - projectIds: z.array(z.string()).optional(), - clientIds: z.array(z.string()).optional(), - chapters: z.array(z.string()).optional(), - eids: z.array(z.string()).optional(), - countryCodes: z.array(z.string()).optional(), -}); - -export const TimelineProjectContextDetailSchema = z.object({ - projectId: z.string(), - startDate: z.string().optional(), - endDate: z.string().optional(), - durationDays: z.number().int().min(1).max(366).optional(), -}); - -export const TimelineProjectIdSchema = z.object({ - projectId: z.string(), -}); - type TimelineWindowFiltersInput = z.infer; export function getAssignmentResourceIds(