mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-11 00:08:37 +01:00
new selfhosted version
This commit is contained in:
28
dashboard/server/api/raw/visits.ts
Normal file
28
dashboard/server/api/raw/visits.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
import { VisitModel } from "@schema/metrics/VisitSchema";
|
||||
import { parseNumberInt } from "~/utils/parseNumber";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const ctx = await getRequestContext(event, 'pid', 'domain', 'range', 'permission:webAnalytics');
|
||||
const { project_id, domain, from, to } = ctx;
|
||||
|
||||
const { page, limit } = getQuery(event);
|
||||
|
||||
const pageValue = parseNumberInt(page, 1);
|
||||
const limitValue = parseNumberInt(limit, 10);
|
||||
const skipValue = (pageValue - 1) * limitValue;
|
||||
|
||||
const websiteMatch = domain ? { website: domain } : {};
|
||||
|
||||
|
||||
const count = await VisitModel.countDocuments({ project_id, ...websiteMatch, created_at: { $gte: new Date(from), $lte: new Date(to) } });
|
||||
|
||||
const result = await VisitModel.find({
|
||||
project_id, ...websiteMatch, created_at: { $gte: new Date(from), $lte: new Date(to) }
|
||||
}, {}, {
|
||||
skip: skipValue, limit: limitValue, sort: { created_at: -1 }
|
||||
})
|
||||
|
||||
return { count, data: result };
|
||||
});
|
||||
Reference in New Issue
Block a user