fix UTC issues

This commit is contained in:
Francis Cao
2024-08-23 19:23:04 -07:00
parent 004ccdc22f
commit a15d0ca94a
6 changed files with 35 additions and 21 deletions

View File

@@ -7,14 +7,17 @@ import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getRealtimeData } from 'queries';
import * as yup from 'yup';
import { REALTIME_RANGE } from 'lib/constants';
import { TimezoneTest } from 'lib/yup';
export interface RealtimeRequestQuery {
websiteId: string;
timezone?: string;
}
const schema = {
GET: yup.object().shape({
websiteId: yup.string().uuid().required(),
timezone: TimezoneTest,
}),
};
@@ -23,7 +26,7 @@ export default async (req: NextApiRequestQueryBody<RealtimeRequestQuery>, res: N
await useValidate(schema, req, res);
if (req.method === 'GET') {
const { websiteId } = req.query;
const { websiteId, timezone } = req.query;
if (!(await canViewWebsite(req.auth, websiteId))) {
return unauthorized(res);
@@ -31,7 +34,7 @@ export default async (req: NextApiRequestQueryBody<RealtimeRequestQuery>, res: N
const startDate = subMinutes(startOfMinute(new Date()), REALTIME_RANGE);
const data = await getRealtimeData(websiteId, { startDate });
const data = await getRealtimeData(websiteId, { startDate, timezone });
return ok(res, data);
}