Files
litlyx/dashboard/server/api/data/live_users.ts
2025-01-21 18:07:01 +01:00

25 lines
577 B
TypeScript

import { SessionModel } from "@schema/metrics/SessionSchema";
export default defineEventHandler(async event => {
const data = await getRequestDataOld(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;
});