2020-08-12 07:24:41 +02:00
|
|
|
import { getMetrics } from 'lib/queries';
|
2020-07-28 08:52:14 +02:00
|
|
|
import { useAuth } from 'lib/middleware';
|
2020-08-08 02:19:42 +02:00
|
|
|
import { ok } from 'lib/response';
|
2020-07-28 08:52:14 +02:00
|
|
|
|
|
|
|
export default async (req, res) => {
|
|
|
|
await useAuth(req, res);
|
|
|
|
|
|
|
|
const { id, start_at, end_at } = req.query;
|
|
|
|
|
2020-08-12 05:05:40 +02:00
|
|
|
const metrics = await getMetrics(+id, new Date(+start_at), new Date(+end_at));
|
2020-07-28 08:52:14 +02:00
|
|
|
|
2020-07-31 05:11:43 +02:00
|
|
|
const stats = Object.keys(metrics[0]).reduce((obj, key) => {
|
|
|
|
obj[key] = +metrics[0][key];
|
2020-07-30 06:40:26 +02:00
|
|
|
return obj;
|
|
|
|
}, {});
|
|
|
|
|
2020-08-08 02:19:42 +02:00
|
|
|
return ok(res, stats);
|
2020-07-28 08:52:14 +02:00
|
|
|
};
|