segments implementation and migration update. update getRequestFilters to include filter groups.

This commit is contained in:
Francis Cao 2025-06-13 07:34:54 -07:00
parent 1ccc8a1a86
commit f61421b742
16 changed files with 188 additions and 23 deletions

View file

@ -1,9 +1,9 @@
import { z } from 'zod';
import { canViewWebsite } from '@/lib/auth';
import { EVENT_COLUMNS, FILTER_COLUMNS, GROUP_FILTERS, SESSION_COLUMNS } from '@/lib/constants';
import { getValues } from '@/queries';
import { parseRequest, getRequestDateRange } from '@/lib/request';
import { EVENT_COLUMNS, FILTER_COLUMNS, FILTER_GROUPS, SESSION_COLUMNS } from '@/lib/constants';
import { getRequestDateRange, parseRequest } from '@/lib/request';
import { badRequest, json, unauthorized } from '@/lib/response';
import { getWebsiteSegments, getValues } from '@/queries';
import { z } from 'zod';
export async function GET(
request: Request,
@ -33,12 +33,18 @@ export async function GET(
if (
!SESSION_COLUMNS.includes(type) &&
!EVENT_COLUMNS.includes(type) &&
!GROUP_FILTERS.includes(type)
!FILTER_GROUPS.includes(type)
) {
return badRequest('Invalid type.');
}
const values = await getValues(websiteId, FILTER_COLUMNS[type], startDate, endDate, search);
let values;
if (FILTER_GROUPS.includes(type)) {
values = (await getWebsiteSegments(websiteId, type)).map(segment => ({ value: segment.name }));
} else {
values = await getValues(websiteId, FILTER_COLUMNS[type], startDate, endDate, search);
}
return json(values.filter(n => n).sort());
}