Merge branch 'dev' into feat/um-114-roles-and-permissions

This commit is contained in:
Brian Cao 2022-12-01 20:30:46 -08:00
parent 3085bdd713
commit ab9f403448
28 changed files with 345 additions and 412 deletions

View file

@ -1,7 +1,6 @@
import { WebsiteMetric } from 'interface/api/models';
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
import { allowQuery } from 'lib/auth';
import { UmamiApi } from 'lib/constants';
import { canViewWebsite } from 'lib/auth';
import { useAuth, useCors } from 'lib/middleware';
import moment from 'moment-timezone';
import { NextApiResponse } from 'next';
@ -27,13 +26,16 @@ export default async (
await useCors(req, res);
await useAuth(req, res);
const {
user: { id: userId },
} = req.auth;
const { id: websiteId, start_at, end_at, unit, tz, url, event_name } = req.query;
if (req.method === 'GET') {
if (!(await allowQuery(req, UmamiApi.AuthType.Website))) {
if (canViewWebsite(userId, websiteId)) {
return unauthorized(res);
}
const { id: websiteId, start_at, end_at, unit, tz, url, event_name } = req.query;
if (!moment.tz.zone(tz) || !unitTypes.includes(unit)) {
return badRequest(res);
}