More yup validations.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user