mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
37 lines
944 B
TypeScript
37 lines
944 B
TypeScript
import { z } from 'zod';
|
|
import { parseRequest } from 'lib/request';
|
|
import { unauthorized, json } from 'lib/response';
|
|
import { canViewWebsite } from 'lib/auth';
|
|
import { pagingParams } from 'lib/schema';
|
|
import { getWebsiteSessions } 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(),
|
|
...pagingParams,
|
|
});
|
|
|
|
const { auth, query, error } = await parseRequest(request, schema);
|
|
|
|
if (error) {
|
|
return error();
|
|
}
|
|
|
|
const { websiteId } = await params;
|
|
const { startAt, endAt } = query;
|
|
|
|
if (!(await canViewWebsite(auth, websiteId))) {
|
|
return unauthorized();
|
|
}
|
|
|
|
const startDate = new Date(+startAt);
|
|
const endDate = new Date(+endAt);
|
|
|
|
const data = await getWebsiteSessions(websiteId, { startDate, endDate }, query);
|
|
|
|
return json(data);
|
|
}
|