Refactored query filters.

This commit is contained in:
Mike Cao 2023-08-04 00:51:52 -07:00
parent b65c478689
commit 157862834d
16 changed files with 118 additions and 147 deletions

View file

@ -11,7 +11,7 @@ export interface InsightsRequestBody {
startDate: string;
endDate: string;
};
fields: string[];
fields: { name: string; type: string; value: string }[];
filters: string[];
groups: string[];
}

View file

@ -46,6 +46,7 @@ export default async (
country,
region,
city,
language,
} = req.query;
if (req.method === 'GET') {
@ -55,19 +56,26 @@ export default async (
const { startDate, endDate } = await parseDateRangeQuery(req);
const filters = {
url,
referrer,
title,
query,
event,
os,
browser,
device,
country,
region,
city,
language,
};
filters[type] = undefined;
const column = FILTER_COLUMNS[type] || type;
if (SESSION_COLUMNS.includes(type)) {
const column = FILTER_COLUMNS[type] || type;
const filters = {
os,
browser,
device,
country,
region,
city,
};
filters[type] = undefined;
const data = await getSessionMetrics(websiteId, {
startDate,
endDate,
@ -95,23 +103,6 @@ export default async (
}
if (EVENT_COLUMNS.includes(type)) {
const column = FILTER_COLUMNS[type] || type;
const filters = {
url,
referrer,
title,
query,
event,
os,
browser,
device,
country,
region,
city,
};
filters[type] = undefined;
const data = await getPageviewMetrics(websiteId, {
startDate,
endDate,