mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 14:17:13 +01:00
translate dateRange and cohort prefix for filtering
This commit is contained in:
parent
65024d4bf7
commit
b2e03390da
8 changed files with 68 additions and 60 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import { z } from 'zod/v4';
|
||||
import { FILTER_COLUMNS, DEFAULT_PAGE_SIZE } from '@/lib/constants';
|
||||
import { badRequest, unauthorized } from '@/lib/response';
|
||||
import { getAllowedUnits, getMinimumUnit, maxDate } from '@/lib/date';
|
||||
import { checkAuth } from '@/lib/auth';
|
||||
import { DEFAULT_PAGE_SIZE, FILTER_COLUMNS } from '@/lib/constants';
|
||||
import { getAllowedUnits, getMinimumUnit, maxDate, parseDateRange } from '@/lib/date';
|
||||
import { fetchWebsite } from '@/lib/load';
|
||||
import { badRequest, unauthorized } from '@/lib/response';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
import { getWebsiteSegment } from '@/queries';
|
||||
import { z } from 'zod/v4';
|
||||
|
||||
export async function parseRequest(
|
||||
request: Request,
|
||||
|
|
@ -104,7 +104,27 @@ export async function getQueryFilters(
|
|||
}
|
||||
|
||||
if (params.cohort) {
|
||||
filters.cohortFilters = (await getWebsiteSegment(websiteId, params.cohort))?.parameters;
|
||||
const cohortFilters = (await getWebsiteSegment(websiteId, params.cohort))
|
||||
?.parameters as Record<string, any>;
|
||||
|
||||
// convert dateRange to startDate and endDate
|
||||
if (cohortFilters.dateRange) {
|
||||
const { startDate, endDate } = parseDateRange(cohortFilters.dateRange);
|
||||
cohortFilters.startDate = startDate;
|
||||
cohortFilters.endDate = endDate;
|
||||
delete cohortFilters.dateRange;
|
||||
}
|
||||
|
||||
Object.assign(
|
||||
filters,
|
||||
Object.fromEntries(
|
||||
Object.entries(cohortFilters || {}).map(([key, value]) =>
|
||||
key === 'startDate' || key === 'endDate'
|
||||
? [`cohort_${key}`, new Date(value)]
|
||||
: [`cohort_${key}`, value],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue