feat(reports): parseOperationalFilters pure parser (Area scope)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
27
src/lib/services/reports/operational-filters.ts
Normal file
27
src/lib/services/reports/operational-filters.ts
Normal 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 };
|
||||
}
|
||||
Reference in New Issue
Block a user