mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Convert event-data, events, session-data, sessions routes.
This commit is contained in:
parent
baa3851fb4
commit
7d5556a637
47 changed files with 692 additions and 136 deletions
44
src/app/api/websites/[websiteId]/event-data/values/route.ts
Normal file
44
src/app/api/websites/[websiteId]/event-data/values/route.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getEventDataValues } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
eventName: z.string().optional(),
|
||||
propertyName: z.string().optional(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt, eventName, propertyName } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataValues(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
eventName,
|
||||
propertyName,
|
||||
});
|
||||
|
||||
return json(data);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue