mirror of
https://github.com/umami-software/umami.git
synced 2026-02-16 18:45:36 +01:00
Renamed methods. Initial work on realtime dashboard.
This commit is contained in:
parent
b4ea70a67c
commit
e64a555652
16 changed files with 246 additions and 86 deletions
28
pages/api/website/[id]/stats.js
Normal file
28
pages/api/website/[id]/stats.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { getWebsiteStats } from 'lib/queries';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
|
||||
export default async (req, res) => {
|
||||
if (req.method === 'GET') {
|
||||
if (!(await allowQuery(req))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { id, start_at, end_at, url } = req.query;
|
||||
|
||||
const websiteId = +id;
|
||||
const startDate = new Date(+start_at);
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
const metrics = await getWebsiteStats(websiteId, startDate, endDate, { url });
|
||||
|
||||
const stats = Object.keys(metrics[0]).reduce((obj, key) => {
|
||||
obj[key] = Number(metrics[0][key]) || 0;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
return ok(res, stats);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue