mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 23:33:37 +01:00
29 lines
846 B
JavaScript
29 lines
846 B
JavaScript
import { getRankings, getEvents } from 'lib/queries';
|
|
import { ok, badRequest } from 'lib/response';
|
|
|
|
const sessionColumns = ['browser', 'os', 'device', 'country'];
|
|
const pageviewColumns = ['url', 'referrer'];
|
|
|
|
export default async (req, res) => {
|
|
const { id, type, start_at, end_at } = req.query;
|
|
const websiteId = +id;
|
|
const startDate = new Date(+start_at);
|
|
const endDate = new Date(+end_at);
|
|
|
|
if (type !== 'event' && !sessionColumns.includes(type) && !pageviewColumns.includes(type)) {
|
|
return badRequest(res);
|
|
}
|
|
|
|
if (type === 'event') {
|
|
const events = await getEvents(websiteId, startDate, endDate);
|
|
|
|
return ok(res, events);
|
|
}
|
|
|
|
const table = sessionColumns.includes(type) ? 'session' : 'pageview';
|
|
|
|
const rankings = await getRankings(websiteId, startDate, endDate, type, table);
|
|
|
|
return ok(res, rankings);
|
|
};
|