1
0
mirror of https://github.com/kremalicious/umami.git synced 2024-12-24 18:26:20 +01:00
umami/pages/api/website/[id]/metrics.js
2020-08-15 01:17:15 -07:00

16 lines
395 B
JavaScript

import { getMetrics } from 'lib/queries';
import { ok } from 'lib/response';
export default async (req, res) => {
const { id, start_at, end_at } = req.query;
const metrics = await getMetrics(+id, new Date(+start_at), new Date(+end_at));
const stats = Object.keys(metrics[0]).reduce((obj, key) => {
obj[key] = +metrics[0][key];
return obj;
}, {});
return ok(res, stats);
};