Converted admin, auth, me and realtime routes.

This commit is contained in:
Mike Cao 2025-01-28 22:29:03 -08:00
parent 6c9f1ad06b
commit 5205551ca8
25 changed files with 346 additions and 7 deletions

View file

@ -0,0 +1,30 @@
import { json, unauthorized } from 'lib/response';
import { getRealtimeData } from 'queries';
import { canViewWebsite } from 'lib/auth';
import { startOfMinute, subMinutes } from 'date-fns';
import { REALTIME_RANGE } from 'lib/constants';
import { parseRequest } from 'lib/request';
export async function GET(
request: Request,
{ params }: { params: Promise<{ websiteId: string }> },
) {
const { auth, query, error } = await parseRequest(request);
if (error) {
return error();
}
const { websiteId } = await params;
const { timezone } = query;
if (!(await canViewWebsite(auth, websiteId))) {
return unauthorized();
}
const startDate = subMinutes(startOfMinute(new Date()), REALTIME_RANGE);
const data = await getRealtimeData(websiteId, { startDate, timezone });
return json(data);
}