2020-07-29 09:16:02 +02:00
|
|
|
import { getSummary } from 'lib/db';
|
2020-07-28 08:52:14 +02:00
|
|
|
import { useAuth } from 'lib/middleware';
|
2020-07-29 09:16:02 +02:00
|
|
|
import { format } from 'date-fns';
|
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-07-29 09:16:02 +02:00
|
|
|
const summary = await getSummary(
|
|
|
|
+id,
|
|
|
|
format(new Date(+start_at), 'yyyy-MM-dd hh:mm:ss'),
|
|
|
|
format(new Date(+end_at), 'yyyy-MM-dd hh:mm:ss'),
|
|
|
|
);
|
2020-07-28 08:52:14 +02:00
|
|
|
|
2020-07-30 06:40:26 +02:00
|
|
|
const stats = Object.keys(summary[0]).reduce((obj, key) => {
|
|
|
|
obj[key] = +summary[0][key];
|
|
|
|
return obj;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
return res.status(200).json(stats);
|
2020-07-28 08:52:14 +02:00
|
|
|
};
|