Use dataStartDate for resetDate.

This commit is contained in:
Mike Cao 2023-07-25 15:17:50 -07:00
parent ee8de858d1
commit 0f98fb5959
15 changed files with 172 additions and 85 deletions

View file

@ -3,11 +3,10 @@ import { NextApiResponse } from 'next';
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
import { NextApiRequestQueryBody, WebsitePageviews } from 'lib/types';
import { canViewWebsite } from 'lib/auth';
import { getAllowedUnits } from 'lib/date';
import { useAuth, useCors } from 'lib/middleware';
import { getPageviewStats } from 'queries';
const unitTypes = ['year', 'month', 'hour', 'day'];
export interface WebsitePageviewRequestQuery {
id: string;
startAt: number;
@ -57,7 +56,7 @@ export default async (
const startDate = new Date(+startAt);
const endDate = new Date(+endAt);
if (!moment.tz.zone(timezone) || !unitTypes.includes(unit)) {
if (!moment.tz.zone(timezone) || !getAllowedUnits(unit).includes(unit)) {
return badRequest(res);
}