mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 07:07:17 +01:00
Refactor part 2: Electric Boogaloo. Standardize way of passing filter parameters.
This commit is contained in:
parent
f26f1b0581
commit
cdf391d5c2
90 changed files with 867 additions and 709 deletions
|
|
@ -3,30 +3,37 @@ import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
|||
import prisma from '@/lib/prisma';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
export interface GoalCriteria {
|
||||
export interface GoalParameters {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
type: string;
|
||||
value: string;
|
||||
operator?: string;
|
||||
property?: string;
|
||||
filters: QueryFilters;
|
||||
}
|
||||
|
||||
export async function getGoal(...args: [websiteId: string, criteria: GoalCriteria]) {
|
||||
export async function getGoal(
|
||||
...args: [websiteId: string, params: GoalParameters, filters: QueryFilters]
|
||||
) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, criteria: GoalCriteria) {
|
||||
const { type, value, filters } = criteria;
|
||||
async function relationalQuery(
|
||||
websiteId: string,
|
||||
parameters: GoalParameters,
|
||||
filters: QueryFilters,
|
||||
) {
|
||||
const { startDate, endDate, type, value } = parameters;
|
||||
const { rawQuery, parseFilters } = prisma;
|
||||
const { filterQuery, dateQuery, queryParams } = await parseFilters({
|
||||
const { filterQuery, dateQuery, queryParams } = parseFilters({
|
||||
...filters,
|
||||
websiteId,
|
||||
value,
|
||||
startDate,
|
||||
endDate,
|
||||
});
|
||||
const isPage = type === 'page';
|
||||
const column = isPage ? 'url_path' : 'event_name';
|
||||
|
|
@ -53,13 +60,19 @@ async function relationalQuery(websiteId: string, criteria: GoalCriteria) {
|
|||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteId: string, criteria: GoalCriteria) {
|
||||
const { type, value, filters } = criteria;
|
||||
async function clickhouseQuery(
|
||||
websiteId: string,
|
||||
parameters: GoalParameters,
|
||||
filters: QueryFilters,
|
||||
) {
|
||||
const { startDate, endDate, type, value } = parameters;
|
||||
const { rawQuery, parseFilters } = clickhouse;
|
||||
const { filterQuery, dateQuery, queryParams } = await parseFilters({
|
||||
const { filterQuery, dateQuery, queryParams } = parseFilters({
|
||||
...filters,
|
||||
websiteId,
|
||||
value,
|
||||
startDate,
|
||||
endDate,
|
||||
});
|
||||
const isPage = type === 'page';
|
||||
const column = isPage ? 'url_path' : 'event_name';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue