Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	src/components/common/Pager.module.css
#	src/lib/constants.ts
#	src/lib/yup.ts
#	src/pages/api/teams/[id]/users/index.ts
#	src/pages/api/websites/[id]/reports.ts
This commit is contained in:
Mike Cao 2023-09-26 23:27:55 -07:00
commit 40cfcd41e9
19 changed files with 135 additions and 92 deletions

View file

@ -1,32 +1,29 @@
import { WebsiteMetric, NextApiRequestQueryBody } from 'lib/types';
import { canViewWebsite } from 'lib/auth';
import { useAuth, useCors, useValidate } from 'lib/middleware';
import moment from 'moment-timezone';
import { NextApiResponse } from 'next';
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getEventMetrics } from 'queries';
import { parseDateRangeQuery } from 'lib/query';
const unitTypes = ['year', 'month', 'hour', 'day'];
import { NextApiRequestQueryBody, WebsiteMetric } from 'lib/types';
import { TimezoneTest, UnitTypeTest } from 'lib/yup';
import { NextApiResponse } from 'next';
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getEventMetrics } from 'queries';
import * as yup from 'yup';
export interface WebsiteEventsRequestQuery {
id: string;
startAt: string;
endAt: string;
unit: string;
timezone: string;
unit?: string;
timezone?: string;
url: string;
}
import * as yup from 'yup';
const schema = {
GET: yup.object().shape({
id: yup.string().uuid().required(),
startAt: yup.number().integer().required(),
endAt: yup.number().integer().moreThan(yup.ref('startAt')).required(),
unit: yup.string().required(),
timezone: yup.string().required(),
unit: UnitTypeTest,
timezone: TimezoneTest,
url: yup.string(),
}),
};
@ -49,10 +46,6 @@ export default async (
return unauthorized(res);
}
if (!moment.tz.zone(timezone) || !unitTypes.includes(unit)) {
return badRequest(res);
}
const events = await getEventMetrics(websiteId, {
startDate,
endDate,

View file

@ -22,6 +22,12 @@ const schema = {
GET: yup.object().shape({
id: yup.string().uuid().required(),
}),
POST: yup.object().shape({
id: yup.string().uuid().required(),
name: yup.string().required(),
domain: yup.string().required(),
shareId: yup.string().matches(SHARE_ID_REGEX, { excludeEmptyString: true }),
}),
};
export default async (
@ -55,10 +61,6 @@ export default async (
let website;
if (shareId && !shareId.match(SHARE_ID_REGEX)) {
return serverError(res, 'Invalid share ID.');
}
try {
website = await updateWebsite(websiteId, { name, domain, shareId });
} catch (e: any) {

View file

@ -33,6 +33,18 @@ const schema = {
type: yup.string().required(),
startAt: yup.number().required(),
endAt: yup.number().required(),
url: yup.string(),
referrer: yup.string(),
title: yup.string(),
query: yup.string(),
os: yup.string(),
browser: yup.string(),
device: yup.string(),
country: yup.string(),
region: yup.string(),
city: yup.string(),
language: yup.string(),
event: yup.string(),
}),
};

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, UnitTypeTest } 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: UnitTypeTest,
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,

View file

@ -4,14 +4,14 @@ import { useAuth, useCors, useValidate } from 'lib/middleware';
import { NextApiResponse } from 'next';
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { resetWebsite } from 'queries';
import * as yup from 'yup';
export interface WebsiteResetRequestQuery {
id: string;
}
import * as yup from 'yup';
const schema = {
GET: yup.object().shape({
POST: yup.object().shape({
id: yup.string().uuid().required(),
}),
};
@ -22,7 +22,6 @@ export default async (
) => {
await useCors(req, res);
await useAuth(req, res);
req.yup = schema;
await useValidate(req, res);

View file

@ -11,23 +11,36 @@ export interface WebsiteStatsRequestQuery {
id: string;
startAt: number;
endAt: number;
url: string;
referrer: string;
title: string;
query: string;
event: string;
os: string;
browser: string;
device: string;
country: string;
region: string;
city: string;
url?: string;
referrer?: string;
title?: string;
query?: string;
event?: string;
os?: string;
browser?: string;
device?: string;
country?: string;
region?: string;
city?: string;
}
import * as yup from 'yup';
const schema = {
GET: yup.object().shape({
id: yup.string().uuid().required(),
startAt: yup.number().required(),
endAt: yup.number().required(),
url: yup.string(),
referrer: yup.string(),
title: yup.string(),
query: yup.string(),
event: yup.string(),
os: yup.string(),
browser: yup.string(),
device: yup.string(),
country: yup.string(),
region: yup.string(),
city: yup.string(),
}),
};