This commit is contained in:
Brian Cao 2022-10-11 19:37:38 -07:00
parent b0bed5e73a
commit c147742d7a
18 changed files with 84 additions and 52 deletions

View file

@ -11,9 +11,7 @@ export default async (req, res) => {
return unauthorized(res);
}
const { id } = req.query;
const websiteId = +id;
const { id: websiteId } = req.query;
const result = await getActiveVisitors(websiteId);

View file

@ -14,13 +14,11 @@ export default async (req, res) => {
return unauthorized(res);
}
const { id, start_at, end_at, unit, tz, url, event_name } = req.query;
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);
}
const websiteId = +id;
const startDate = new Date(+start_at);
const endDate = new Date(+end_at);

View file

@ -1,14 +1,10 @@
import { methodNotAllowed, ok, unauthorized, getRandomChars } from 'next-basics';
import { deleteWebsite, getAccount, getWebsite, updateWebsite } from 'queries';
import { allowQuery } from 'lib/auth';
import { useAuth, useCors } from 'lib/middleware';
import { validate } from 'uuid';
import { getRandomChars, methodNotAllowed, ok, unauthorized } from 'next-basics';
import { deleteWebsite, getAccount, getWebsite, getWebsiteByUuid, updateWebsite } from 'queries';
export default async (req, res) => {
const { id } = req.query;
const websiteId = +id;
const where = validate(id) ? { websiteUuid: id } : { id: +id };
const { id: websiteId } = req.query;
if (req.method === 'GET') {
await useCors(req, res);
@ -17,7 +13,7 @@ export default async (req, res) => {
return unauthorized(res);
}
const website = await getWebsite(where);
const website = await getWebsiteByUuid(websiteId);
return ok(res, website);
}
@ -33,7 +29,7 @@ export default async (req, res) => {
account = await getAccount({ accountUuid });
}
const website = await getWebsite(where);
const website = await getWebsite(websiteId);
const shareId = enable_share_url ? website.shareId || getRandomChars(8) : null;
@ -48,7 +44,7 @@ export default async (req, res) => {
shareId: shareId,
userId: account ? account.id : +owner,
},
where,
{ websiteUuid: websiteId },
);
return ok(res);

View file

@ -1,8 +1,8 @@
import { getPageviewMetrics, getSessionMetrics, getWebsiteById } from 'queries';
import { ok, methodNotAllowed, unauthorized, badRequest } from 'next-basics';
import { allowQuery } from 'lib/auth';
import { useCors } from 'lib/middleware';
import { FILTER_IGNORED } from 'lib/constants';
import { useCors } from 'lib/middleware';
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getPageviewMetrics, getSessionMetrics, getWebsiteByUuid } from 'queries';
const sessionColumns = ['browser', 'os', 'device', 'screen', 'country', 'language'];
const pageviewColumns = ['url', 'referrer', 'query'];
@ -41,9 +41,19 @@ export default async (req, res) => {
return unauthorized(res);
}
const { id, type, start_at, end_at, url, referrer, os, browser, device, country } = req.query;
const {
id: websiteId,
type,
start_at,
end_at,
url,
referrer,
os,
browser,
device,
country,
} = req.query;
const websiteId = +id;
const startDate = new Date(+start_at);
const endDate = new Date(+end_at);
@ -83,7 +93,7 @@ export default async (req, res) => {
let domain;
if (type === 'referrer') {
const website = await getWebsiteById(websiteId);
const website = await getWebsiteByUuid(websiteId);
if (!website) {
return badRequest(res);

View file

@ -14,10 +14,20 @@ export default async (req, res) => {
return unauthorized(res);
}
const { id, start_at, end_at, unit, tz, url, referrer, os, browser, device, country } =
req.query;
const {
id: websiteId,
start_at,
end_at,
unit,
tz,
url,
referrer,
os,
browser,
device,
country,
} = req.query;
const websiteId = +id;
const startDate = new Date(+start_at);
const endDate = new Date(+end_at);

View file

@ -3,8 +3,7 @@ import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { allowQuery } from 'lib/auth';
export default async (req, res) => {
const { id } = req.query;
const websiteId = +id;
const { id: websiteId } = req.query;
if (req.method === 'POST') {
if (!(await allowQuery(req))) {

View file

@ -11,9 +11,18 @@ export default async (req, res) => {
return unauthorized(res);
}
const { website_id, start_at, end_at, url, referrer, os, browser, device, country } = req.query;
const {
id: websiteId,
start_at,
end_at,
url,
referrer,
os,
browser,
device,
country,
} = req.query;
const websiteId = +website_id;
const startDate = new Date(+start_at);
const endDate = new Date(+end_at);