mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Events chart.
This commit is contained in:
parent
5f47f328be
commit
4618dc7f15
9 changed files with 220 additions and 226 deletions
21
pages/api/website/[id]/events.js
Normal file
21
pages/api/website/[id]/events.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import moment from 'moment-timezone';
|
||||
import { getEvents } from 'lib/queries';
|
||||
import { ok, badRequest } from 'lib/response';
|
||||
|
||||
const unitTypes = ['month', 'hour', 'day'];
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id, start_at, end_at, unit, tz } = 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);
|
||||
|
||||
const events = await getEvents(websiteId, startDate, endDate, tz, unit);
|
||||
|
||||
return ok(res, events);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue