Use getRequestDateRange in all routes.

This commit is contained in:
Mike Cao 2025-06-25 22:53:07 -07:00
parent b0023feee9
commit 5171bdaf47
21 changed files with 72 additions and 173 deletions

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { getRequestDateRange, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { getEventDataEvents } from '@/queries/sql/events/getEventDataEvents';
@ -20,15 +20,13 @@ export async function GET(
}
const { websiteId } = await params;
const { startAt, endAt, event } = query;
const { event } = query;
const { startDate, endDate } = await getRequestDateRange(query);
if (!(await canViewWebsite(auth, websiteId))) {
return unauthorized();
}
const startDate = new Date(+startAt);
const endDate = new Date(+endAt);
const data = await getEventDataEvents(websiteId, {
startDate,
endDate,

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { getRequestDateRange, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { getEventDataFields } from '@/queries';
@ -20,15 +20,12 @@ export async function GET(
}
const { websiteId } = await params;
const { startAt, endAt } = query;
const { startDate, endDate } = await getRequestDateRange(query);
if (!(await canViewWebsite(auth, websiteId))) {
return unauthorized();
}
const startDate = new Date(+startAt);
const endDate = new Date(+endAt);
const data = await getEventDataFields(websiteId, {
startDate,
endDate,

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { getRequestDateRange, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { getEventDataProperties } from '@/queries';
@ -21,15 +21,13 @@ export async function GET(
}
const { websiteId } = await params;
const { startAt, endAt, propertyName } = query;
const { propertyName } = query;
const { startDate, endDate } = await getRequestDateRange(query);
if (!(await canViewWebsite(auth, websiteId))) {
return unauthorized();
}
const startDate = new Date(+startAt);
const endDate = new Date(+endAt);
const data = await getEventDataProperties(websiteId, { startDate, endDate, propertyName });
return json(data);

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { getRequestDateRange, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { getEventDataStats } from '@/queries';
@ -21,15 +21,12 @@ export async function GET(
}
const { websiteId } = await params;
const { startAt, endAt } = query;
const { startDate, endDate } = await getRequestDateRange(query);
if (!(await canViewWebsite(auth, websiteId))) {
return unauthorized();
}
const startDate = new Date(+startAt);
const endDate = new Date(+endAt);
const data = await getEventDataStats(websiteId, { startDate, endDate });
return json(data);

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { getRequestDateRange, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { getEventDataValues } from '@/queries';
@ -22,15 +22,13 @@ export async function GET(
}
const { websiteId } = await params;
const { startAt, endAt, eventName, propertyName } = query;
const { eventName, propertyName } = query;
const { startDate, endDate } = await getRequestDateRange(query);
if (!(await canViewWebsite(auth, websiteId))) {
return unauthorized();
}
const startDate = new Date(+startAt);
const endDate = new Date(+endAt);
const data = await getEventDataValues(websiteId, {
startDate,
endDate,