Merge branch 'dev' into feat/um-185-event-data-redirect

This commit is contained in:
Brian Cao 2023-03-01 16:40:06 -08:00
commit 53a6a8924d
23 changed files with 3791 additions and 98 deletions

View file

@ -1,7 +1,6 @@
import { WebsiteStats } from 'lib/types';
import { NextApiRequestQueryBody } from 'lib/types';
import { canViewWebsite } from 'lib/auth';
import { useAuth, useCors } from 'lib/middleware';
import { NextApiRequestQueryBody, WebsiteStats } from 'lib/types';
import { NextApiResponse } from 'next';
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getWebsiteStats } from 'queries';
@ -13,10 +12,14 @@ export interface WebsiteStatsRequestQuery {
endAt: number;
url: string;
referrer: string;
pageTitle: string;
os: string;
browser: string;
device: string;
country: string;
subdivision1: string;
subdivision2: string;
city: string;
}
export default async (
@ -26,7 +29,21 @@ export default async (
await useCors(req, res);
await useAuth(req, res);
const { id: websiteId, startAt, endAt, url, referrer, os, browser, device, country } = req.query;
const {
id: websiteId,
startAt,
endAt,
url,
referrer,
pageTitle,
os,
browser,
device,
country,
subdivision1,
subdivision2,
city,
} = req.query;
if (req.method === 'GET') {
if (!(await canViewWebsite(req.auth, websiteId))) {
@ -46,10 +63,14 @@ export default async (
filters: {
url,
referrer,
pageTitle,
os,
browser,
device,
country,
subdivision1,
subdivision2,
city,
},
});
const prevPeriod = await getWebsiteStats(websiteId, {
@ -58,10 +79,14 @@ export default async (
filters: {
url,
referrer,
pageTitle,
os,
browser,
device,
country,
subdivision1,
subdivision2,
city,
},
});