Add eventData back.

This commit is contained in:
Brian Cao 2023-03-23 00:36:38 -07:00
parent 30d2163610
commit 0d3c159084
9 changed files with 313 additions and 5 deletions

View file

@ -2,6 +2,7 @@ import prisma from '@umami/prisma-client';
import moment from 'moment-timezone';
import { MYSQL, POSTGRESQL, getDatabaseType } from 'lib/db';
import { FILTER_IGNORED } from 'lib/constants';
import { getEventDataType } from './eventData';
const MYSQL_DATE_FORMATS = {
minute: '%Y-%m-%d %H:%i:00',
@ -64,6 +65,46 @@ function getTimestampInterval(field: string): string {
}
}
function getEventDataFilterQuery(
filters: {
eventKey?: string;
eventValue?: string | number | boolean | Date;
}[],
params: any[],
) {
const query = filters.reduce((ac, cv, i) => {
const type = getEventDataType(cv);
let value = cv.eventValue;
switch (type) {
case 'number':
ac.push(`and event_numeric_value = {${cv.eventKey}${i}:UInt64}`);
params.push(cv.eventValue);
break;
case 'string':
ac.push(`and event_string_value = {${cv.eventKey}${i}:String}`);
params.push(decodeURIComponent(cv.eventValue as string));
break;
case 'boolean':
ac.push(`and event_string_value = {${cv.eventKey}${i}:String}`);
params.push(decodeURIComponent(cv.eventValue as string));
value = cv ? 'true' : 'false';
break;
case 'date':
ac.push(`and event_date_value = {${cv.eventKey}${i}:DateTime('UTC')}`);
params.push(cv.eventValue);
break;
}
params[`${cv.eventKey}${i}`] = value;
return ac;
}, []);
return query.join('\n');
}
function getFilterQuery(filters = {}, params = []): string {
const query = Object.keys(filters).reduce((arr, key) => {
const filter = filters[key];
@ -173,6 +214,7 @@ export default {
getDateQuery,
getTimestampInterval,
getFilterQuery,
getEventDataFilterQuery,
toUuid,
parseFilters,
rawQuery,