(
request: Request,
{ params }: { params: Promise<{ websiteId: string }> },
)
| 7 | import { getValues } from '@/queries/sql'; |
| 8 | |
| 9 | export async function GET( |
| 10 | request: Request, |
| 11 | { params }: { params: Promise<{ websiteId: string }> }, |
| 12 | ) { |
| 13 | const schema = withDateRange({ |
| 14 | type: fieldsParam, |
| 15 | ...searchParams, |
| 16 | }); |
| 17 | |
| 18 | const { auth, query, error } = await parseRequest(request, schema); |
| 19 | |
| 20 | if (error) { |
| 21 | return error(); |
| 22 | } |
| 23 | |
| 24 | const { websiteId } = await params; |
| 25 | |
| 26 | if ( |
| 27 | !(await canViewWebsiteSection(auth, websiteId, [ |
| 28 | 'overview', |
| 29 | 'events', |
| 30 | 'sessions', |
| 31 | 'compare', |
| 32 | 'breakdown', |
| 33 | 'utm', |
| 34 | 'attribution', |
| 35 | ])) |
| 36 | ) { |
| 37 | return unauthorized(); |
| 38 | } |
| 39 | |
| 40 | const { type } = query; |
| 41 | |
| 42 | if (!SESSION_COLUMNS.includes(type) && !EVENT_COLUMNS.includes(type) && !SEGMENT_TYPES[type]) { |
| 43 | return badRequest(); |
| 44 | } |
| 45 | |
| 46 | let values: any[]; |
| 47 | |
| 48 | if (SEGMENT_TYPES[type]) { |
| 49 | values = (await getWebsiteSegments(websiteId, type))?.data?.map(segment => ({ |
| 50 | value: segment.name, |
| 51 | })); |
| 52 | } else { |
| 53 | const filters = await getQueryFilters(query, websiteId); |
| 54 | values = await getValues(websiteId, FILTER_COLUMNS[type], filters); |
| 55 | } |
| 56 | |
| 57 | return json(values.filter(n => n).sort()); |
| 58 | } |
nothing calls this directly
no test coverage detected