MCPcopy
hub / github.com/umami-software/umami / GET

Function GET

src/app/api/websites/[websiteId]/values/route.ts:9–58  ·  view source on GitHub ↗
(
  request: Request,
  { params }: { params: Promise<{ websiteId: string }> },
)

Source from the content-addressed store, hash-verified

7import { getValues } from '@/queries/sql';
8
9export 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}

Callers

nothing calls this directly

Calls 10

withDateRangeFunction · 0.90
parseRequestFunction · 0.90
canViewWebsiteSectionFunction · 0.90
unauthorizedFunction · 0.90
badRequestFunction · 0.90
getWebsiteSegmentsFunction · 0.90
getQueryFiltersFunction · 0.90
getValuesFunction · 0.90
jsonFunction · 0.90
errorFunction · 0.85

Tested by

no test coverage detected