This commit is contained in:
Emily
2024-10-07 15:26:57 +02:00
parent c2846ca595
commit b27cacf4e6
50 changed files with 512 additions and 583 deletions

View File

@@ -0,0 +1,25 @@
import { SessionModel } from "@schema/metrics/SessionSchema";
export default defineEventHandler(async event => {
const data = await getRequestData(event, { requireSchema: false });
if (!data) return;
const { project_id } = data;
const online_users = await SessionModel.aggregate([
{
$match: {
project_id,
updated_at: { $gt: new Date(Date.now() - 1000 * 60 * 5) }
}
},
{ $count: 'count' }
]);
if (!online_users[0]) return 0;
return online_users[0].count;
});