mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
add dashboard
This commit is contained in:
29
dashboard/server/api/metrics/[project_id]/visits/events.ts
Normal file
29
dashboard/server/api/metrics/[project_id]/visits/events.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import { ProjectModel } from "@schema/ProjectSchema";
|
||||
import { EventModel } from "@schema/metrics/EventSchema";
|
||||
|
||||
export type CustomEventsAggregated = {
|
||||
_id: string,
|
||||
count: number
|
||||
}
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
const project_id = getRequestProjectId(event);
|
||||
if (!project_id) return;
|
||||
|
||||
const user = getRequestUser(event);
|
||||
const project = await getUserProjectFromId(project_id, user);
|
||||
if (!project) return;
|
||||
|
||||
|
||||
const websites: CustomEventsAggregated[] = await EventModel.aggregate([
|
||||
{ $match: { project_id: project._id }, },
|
||||
{ $group: { _id: "$name", count: { $sum: 1, } } },
|
||||
{ $sort: { count: -1 } }
|
||||
]);
|
||||
|
||||
return websites;
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user