mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
Updates to insights, event data, telemetry.
This commit is contained in:
parent
39562d4a64
commit
e4bd314bd6
44 changed files with 413 additions and 278 deletions
39
pages/api/event-data/events.ts
Normal file
39
pages/api/event-data/events.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { canViewWebsite } from 'lib/auth';
|
||||
import { useCors, useAuth } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
||||
import { getEventDataEvents } from 'queries';
|
||||
|
||||
export interface EventDataFieldsRequestBody {
|
||||
websiteId: string;
|
||||
dateRange: {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<any, EventDataFieldsRequestBody>,
|
||||
res: NextApiResponse<any>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const { websiteId, startAt, endAt, field, event } = req.query;
|
||||
|
||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const data = await getEventDataEvents(websiteId, new Date(+startAt), new Date(+endAt), {
|
||||
field,
|
||||
event,
|
||||
});
|
||||
|
||||
return ok(res, data);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
|
|
@ -21,20 +21,13 @@ export default async (
|
|||
await useAuth(req, res);
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const { websiteId, startAt, endAt, field, event, withEventNames } = req.query;
|
||||
const { websiteId, startAt, endAt, field } = req.query;
|
||||
|
||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const data = await getEventDataFields(
|
||||
websiteId,
|
||||
new Date(+startAt),
|
||||
new Date(+endAt),
|
||||
field,
|
||||
event,
|
||||
withEventNames,
|
||||
);
|
||||
const data = await getEventDataFields(websiteId, new Date(+startAt), new Date(+endAt), field);
|
||||
|
||||
return ok(res, data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue