web / lib/utils/event-filters
lib/utils/event-filters
Shared utilities for building event filter objects with access control.
This module consolidates the filter building logic used across event API routes. It handles catalog access control, ensuring users can only query catalogs they have permission to access.
Interfaces
EventFilters
Event filters for SQL/Drizzle queries.
Properties
catalogId?
optionalcatalogId:number
Single catalog ID when user has access
catalogIds?
optionalcatalogIds:number[]
Multiple catalog IDs when filtering by accessible catalogs
datasets?
optionaldatasets:number[]
Array of dataset IDs to filter by
startDate?
optionalstartDate:null|string
Start date for temporal filtering
endDate?
optionalendDate:null|string
End date for temporal filtering
bounds?
optionalbounds:object
Geographic bounds for spatial filtering
minLng
minLng:
number
maxLng
maxLng:
number
minLat
minLat:
number
maxLat
maxLat:
number
BuildFiltersOptions
Options for building event filters.
Properties
parameters
parameters:
BaseEventParameters
Event parameters from request
accessibleCatalogIds
accessibleCatalogIds:
number[]
Catalog IDs the user has access to
bounds?
optionalbounds:null|MapBounds
Optional geographic bounds
parseDatasetIds?
optionalparseDatasetIds:boolean
Parse dataset IDs as integers (default: true)
Functions
buildEventFilters()
buildEventFilters(
options):EventFilters
Build event filters with access control logic.
This function handles the common pattern of:
- If a specific catalog is requested and user has access, filter by that catalog
- If a specific catalog is requested but user lacks access, filter by all accessible catalogs
- If no catalog is specified, filter by all accessible catalogs
Parameters
options
Filter building options
Returns
Event filters with access control applied
buildMapClusterFilters()
buildMapClusterFilters(
parameters,accessibleCatalogIds):Record<string,unknown>
Build filters for map clusters query (uses string catalog, not parsed).
This is a specialized version for the map-clusters endpoint which passes catalog as a string to the cluster_events SQL function.
Parameters
parameters
Event parameters from request
accessibleCatalogIds
number[]
Catalog IDs the user has access to
Returns
Record<string, unknown>
Filters with catalog as string for SQL function