mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 15:17:23 +01:00
Support contains queries in overview page.
This commit is contained in:
commit
d945ed3a23
12 changed files with 75 additions and 105 deletions
|
|
@ -1,6 +1,13 @@
|
|||
import { NextApiRequest } from 'next';
|
||||
import { getAllowedUnits, getMinimumUnit } from './date';
|
||||
import { getWebsiteDateRange } from '../queries';
|
||||
import { FILTER_COLUMNS, OPERATORS } from 'lib/constants';
|
||||
|
||||
const OPERATOR_SYMBOLS = {
|
||||
'!': 'neq',
|
||||
'~': 'c',
|
||||
'!~': 'dnc',
|
||||
};
|
||||
|
||||
export async function parseDateRangeQuery(req: NextApiRequest) {
|
||||
const { websiteId, startAt, endAt, unit } = req.query;
|
||||
|
|
@ -29,3 +36,28 @@ export async function parseDateRangeQuery(req: NextApiRequest) {
|
|||
unit: (getAllowedUnits(startDate, endDate).includes(unit as string) ? unit : minUnit) as string,
|
||||
};
|
||||
}
|
||||
|
||||
export function getQueryFilters(req: NextApiRequest) {
|
||||
return Object.keys(FILTER_COLUMNS).reduce((obj, key) => {
|
||||
const value = req.query[key];
|
||||
|
||||
if (value) {
|
||||
obj[key] = value;
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
const [, prefix, paramValue] = value.match(/^(!~|!|~)?(.*)$/);
|
||||
|
||||
if (prefix && paramValue) {
|
||||
obj[key] = {
|
||||
name: key,
|
||||
column: FILTER_COLUMNS[key],
|
||||
operator: OPERATOR_SYMBOLS[prefix] || OPERATORS.equals,
|
||||
value: paramValue,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue