More yup validations.

This commit is contained in:
Brian Cao
2023-09-25 13:19:56 -07:00
parent 2ccb8d0a3c
commit ce2a83a09f
12 changed files with 99 additions and 50 deletions

View File

@@ -1,18 +1,17 @@
import moment from 'moment-timezone';
import { NextApiResponse } from 'next';
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
import { NextApiRequestQueryBody, WebsitePageviews } from 'lib/types';
import { canViewWebsite } from 'lib/auth';
import { useAuth, useCors, useValidate } from 'lib/middleware';
import { getPageviewStats, getSessionStats } from 'queries';
import { parseDateRangeQuery } from 'lib/query';
import { NextApiRequestQueryBody, WebsitePageviews } from 'lib/types';
import { NextApiResponse } from 'next';
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getPageviewStats, getSessionStats } from 'queries';
export interface WebsitePageviewRequestQuery {
id: string;
startAt: number;
endAt: number;
unit: string;
timezone: string;
unit?: string;
timezone?: string;
url?: string;
referrer?: string;
title?: string;
@@ -24,10 +23,24 @@ export interface WebsitePageviewRequestQuery {
city?: string;
}
import { TimezoneTest } from 'lib/yup';
import * as yup from 'yup';
const schema = {
GET: yup.object().shape({
id: yup.string().uuid().required(),
startAt: yup.number().required(),
endAt: yup.number().required(),
unit: yup.string(),
timezone: TimezoneTest,
url: yup.string(),
referrer: yup.string(),
title: yup.string(),
os: yup.string(),
browser: yup.string(),
device: yup.string(),
country: yup.string(),
region: yup.string(),
city: yup.string(),
}),
};
@@ -62,10 +75,6 @@ export default async (
const { startDate, endDate, unit } = await parseDateRangeQuery(req);
if (!moment.tz.zone(timezone)) {
return badRequest(res);
}
const filters = {
startDate,
endDate,