Added useFilterQuery. Converted websites and reports pages.

This commit is contained in:
Mike Cao 2023-09-26 23:20:29 -07:00
parent 6846355c63
commit 7e626dcd52
29 changed files with 373 additions and 499 deletions

View file

@ -1,11 +1,11 @@
import { Prisma } from '@prisma/client';
import prisma from '@umami/prisma-client';
import moment from 'moment-timezone';
import { MYSQL, POSTGRESQL, getDatabaseType } from 'lib/db';
import { FILTER_COLUMNS, SESSION_COLUMNS, OPERATORS } from './constants';
import { FILTER_COLUMNS, SESSION_COLUMNS, OPERATORS, DEFAULT_PAGE_SIZE } from './constants';
import { loadWebsite } from './load';
import { maxDate } from './date';
import { QueryFilters, QueryOptions, SearchFilter } from './types';
import { Prisma } from '@prisma/client';
const MYSQL_DATE_FORMATS = {
minute: '%Y-%m-%d %H:%i:00',
@ -171,7 +171,7 @@ async function rawQuery(sql: string, data: object): Promise<any> {
return prisma.rawQuery(query, params);
}
function getPageFilters(filters: SearchFilter<any>): [
function getPageFilters(filters: SearchFilter): [
{
orderBy: {
[x: string]: string;
@ -185,7 +185,7 @@ function getPageFilters(filters: SearchFilter<any>): [
orderBy: string;
},
] {
const { pageSize = 10, page = 1, orderBy } = filters || {};
const { page = 1, pageSize = DEFAULT_PAGE_SIZE, orderBy } = filters || {};
return [
{
@ -198,7 +198,7 @@ function getPageFilters(filters: SearchFilter<any>): [
],
}),
},
{ pageSize, page: +page, orderBy },
{ page: +page, pageSize, orderBy },
];
}