web / lib/services/aggregation-filters
lib/services/aggregation-filters
Shared filter building utilities for event aggregation queries.
Provides reusable functions to build SQL WHERE clauses from filter parameters, ensuring consistent access control and filter application across all aggregation endpoints.
Interfaces
AggregationFilters
Filter parameters for event aggregation.
Properties
catalog?
optionalcatalog:null|string
Catalog ID to filter by (with access control)
datasets?
optionaldatasets:null|string[]
Dataset IDs to filter by (comma-separated)
startDate?
optionalstartDate:null|string
Start date for event timestamp filter (inclusive)
endDate?
optionalendDate:null|string
End date for event timestamp filter (inclusive to end of day)
bounds?
optionalbounds:null|SimpleBounds
Geographic bounding box for location filtering
Functions
buildAggregationWhereClause()
buildAggregationWhereClause(
filters,accessibleCatalogIds):SQL<unknown>
Build SQL WHERE clause fragments from filter parameters.
Generates SQL conditions for filtering events based on catalog, datasets, date range, and geographic bounds. Always enforces access control by restricting results to accessible catalog IDs.
Parameters
filters
Filter parameters from request
accessibleCatalogIds
number[]
Catalog IDs the user has permission to access
Returns
SQL<unknown>
SQL WHERE clause fragment
Example
const filters = {
catalog: "1",
datasets: ["5", "6"],
startDate: "2024-01-01",
endDate: "2024-12-31",
bounds: { north: 37.8, south: 37.7, east: -122.4, west: -122.5 }
};
const whereClause = buildAggregationWhereClause(filters, [1, 2, 3]);normalizeEndDate()
normalizeEndDate(
endDate):null|string
Normalize end date to include full day (23:59:59.999).
Ensures that date range filtering includes events from the entire end date, not just midnight of that day.
Parameters
endDate
ISO date string (e.g., “2024-12-31”)
null | string
Returns
null | string
ISO datetime string with time set to end of day, or null if input is null
Example
normalizeEndDate("2024-12-31")
// Returns: "2024-12-31T23:59:59.999Z"