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

@ -6,9 +6,11 @@ import { NextApiResponse } from 'next';
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { pageInfo } from 'lib/schema';
import { getWebsiteSessionsWeekly } from 'queries';
import { TimezoneTest } from 'lib/yup';
export interface ReportsRequestQuery extends PageParams {
websiteId: string;
timezone?: string;
}
const schema = {
@ -16,6 +18,7 @@ const schema = {
websiteId: yup.string().uuid().required(),
startAt: yup.number().integer().required(),
endAt: yup.number().integer().min(yup.ref('startAt')).required(),
timezone: TimezoneTest,
...pageInfo,
}),
};
@ -28,7 +31,7 @@ export default async (
await useAuth(req, res);
await useValidate(schema, req, res);
const { websiteId, startAt, endAt } = req.query;
const { websiteId, startAt, endAt, timezone } = req.query;
if (req.method === 'GET') {
if (!(await canViewWebsite(req.auth, websiteId))) {
@ -38,7 +41,7 @@ export default async (
const startDate = new Date(+startAt);
const endDate = new Date(+endAt);
const data = await getWebsiteSessionsWeekly(websiteId, { startDate, endDate });
const data = await getWebsiteSessionsWeekly(websiteId, { startDate, endDate, timezone });
return ok(res, data);
}