mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 23:57:12 +01:00
Feat/um 49 query builder api (#1573)
* add uuid to event. add indexes * eventdata api * add event data * remove test data * update list
This commit is contained in:
parent
9c36dc485e
commit
ba31f48f1a
32 changed files with 690 additions and 64 deletions
40
pages/api/websites/[id]/eventdata.js
Normal file
40
pages/api/websites/[id]/eventdata.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import moment from 'moment-timezone';
|
||||
import { getEventData } from 'queries';
|
||||
import { ok, badRequest, methodNotAllowed, unauthorized } from 'next-basics';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
if (req.method === 'POST') {
|
||||
if (!(await allowQuery(req))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { id: websiteId } = req.query;
|
||||
|
||||
const { start_at, end_at, timezone, event_name: eventName, columns, filters } = req.body;
|
||||
|
||||
if (!moment.tz.zone(timezone)) {
|
||||
return badRequest(res);
|
||||
}
|
||||
|
||||
const startDate = new Date(+start_at);
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
const events = await getEventData(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
timezone,
|
||||
eventName,
|
||||
columns,
|
||||
filters,
|
||||
});
|
||||
|
||||
return ok(res, events);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue