feat(reports): parseOperationalFilters pure parser (Area scope)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-02 10:08:16 +02:00
parent 93e96da43b
commit 3d9084c94b
2 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/**
* Operational report filters. Mirrors `sales-filters.ts`: the parser is a
* pure, unit-testable function so the route just hands it the query params.
*
* Beta scope is Area only (a berth-area scope). The shape is intentionally
* an object so a Status dimension can be added later without a rename.
*/
export interface OperationalFilters {
areas?: string[];
}
/**
* Parse the `area` CSV query param into a free list of port-defined area
* strings. Empty / whitespace entries are dropped. Drizzle parameterises
* the downstream `inArray`, so unvalidated values are injection-safe.
* Returns `undefined` when no areas are active (→ no filter).
*/
export function parseOperationalFilters(params: URLSearchParams): OperationalFilters | undefined {
const raw = params.get('area');
if (!raw) return undefined;
const areas = raw
.split(',')
.map((s) => s.trim())
.filter((s) => s.length > 0);
if (areas.length === 0) return undefined;
return { areas };
}