2022-08-29 05:20:54 +02:00
|
|
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
2020-09-18 07:52:20 +02:00
|
|
|
import { allowQuery } from 'lib/auth';
|
2022-10-12 22:11:44 +02:00
|
|
|
import { useAuth, useCors } from 'lib/middleware';
|
2022-07-12 23:14:36 +02:00
|
|
|
import { getActiveVisitors } from 'queries';
|
2022-10-26 01:50:12 +02:00
|
|
|
import { TYPE_WEBSITE } from 'lib/constants';
|
2020-08-18 09:51:32 +02:00
|
|
|
|
|
|
|
export default async (req, res) => {
|
2022-10-12 22:11:44 +02:00
|
|
|
await useCors(req, res);
|
|
|
|
await useAuth(req, res);
|
2022-04-04 09:33:20 +02:00
|
|
|
|
2022-10-12 22:11:44 +02:00
|
|
|
if (req.method === 'GET') {
|
2022-10-26 01:50:12 +02:00
|
|
|
if (!(await allowQuery(req, TYPE_WEBSITE))) {
|
2020-09-18 07:52:20 +02:00
|
|
|
return unauthorized(res);
|
|
|
|
}
|
|
|
|
|
2022-10-12 04:37:38 +02:00
|
|
|
const { id: websiteId } = req.query;
|
2020-09-18 07:52:20 +02:00
|
|
|
|
2022-10-11 02:01:48 +02:00
|
|
|
const result = await getActiveVisitors(websiteId);
|
2020-09-11 22:49:43 +02:00
|
|
|
|
|
|
|
return ok(res, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return methodNotAllowed(res);
|
2020-08-18 09:51:32 +02:00
|
|
|
};
|