Added parseDateRangeQuery function.

This commit is contained in:
Mike Cao 2023-07-25 23:59:08 -07:00
parent a0aaeeeb57
commit 09af33c77e
15 changed files with 139 additions and 98 deletions

View file

@ -2,8 +2,8 @@ import prisma from 'lib/prisma';
import clickhouse from 'lib/clickhouse';
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
import { EVENT_TYPE } from 'lib/constants';
import { loadWebsite } from 'lib/query';
import { max } from 'date-fns';
import { loadWebsite } from 'lib/load';
import { maxDate } from 'lib/date';
export async function getPageviewMetrics(
...args: [
@ -36,7 +36,7 @@ async function relationalQuery(
const website = await loadWebsite(websiteId);
const params: any = {
websiteId,
startDate: max([startDate, website.resetAt]),
startDate: maxDate(startDate, website.resetAt),
endDate,
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
};
@ -84,7 +84,7 @@ async function clickhouseQuery(
const website = await loadWebsite(websiteId);
const params = {
websiteId,
startDate: max([startDate, website.resetAt]),
startDate: maxDate(startDate, website.resetAt),
endDate,
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
domain: undefined,

View file

@ -2,8 +2,8 @@ import clickhouse from 'lib/clickhouse';
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
import prisma from 'lib/prisma';
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
import { loadWebsite } from 'lib/query';
import { max } from 'date-fns';
import { loadWebsite } from 'lib/load';
import { maxDate } from 'lib/date';
export async function getPageviewStats(
...args: [
@ -66,7 +66,7 @@ async function relationalQuery(
{
...filters,
websiteId,
startDate: max([startDate, website.resetAt]),
startDate: maxDate(startDate, website.resetAt),
endDate,
eventType: EVENT_TYPE.pageView,
},
@ -118,7 +118,7 @@ async function clickhouseQuery(
{
...filters,
websiteId,
startDate: max([startDate, website.resetAt]),
startDate: maxDate(startDate, website.resetAt),
endDate,
eventType: EVENT_TYPE.pageView,
},