mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 21:57:16 +01:00
Session properties.
This commit is contained in:
parent
deb9dd60df
commit
fc1fc5807e
10 changed files with 64 additions and 22 deletions
|
|
@ -6,7 +6,7 @@ import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|||
import { getSessionDataProperties } from 'queries';
|
||||
import * as yup from 'yup';
|
||||
|
||||
export interface EventDataFieldsRequestQuery {
|
||||
export interface SessionDataFieldsRequestQuery {
|
||||
websiteId: string;
|
||||
startAt: string;
|
||||
endAt: string;
|
||||
|
|
@ -23,7 +23,7 @@ const schema = {
|
|||
};
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<EventDataFieldsRequestQuery>,
|
||||
req: NextApiRequestQueryBody<SessionDataFieldsRequestQuery>,
|
||||
res: NextApiResponse<any>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
|
|
|
|||
|
|
@ -9,12 +9,16 @@ import { getSessionActivity } from 'queries';
|
|||
export interface SessionActivityRequestQuery extends PageParams {
|
||||
websiteId: string;
|
||||
sessionId: string;
|
||||
startAt: number;
|
||||
endAt: number;
|
||||
}
|
||||
|
||||
const schema = {
|
||||
GET: yup.object().shape({
|
||||
websiteId: yup.string().uuid().required(),
|
||||
sessionId: yup.string().uuid().required(),
|
||||
startAt: yup.number().integer(),
|
||||
endAt: yup.number().integer(),
|
||||
}),
|
||||
};
|
||||
|
||||
|
|
@ -26,14 +30,17 @@ export default async (
|
|||
await useAuth(req, res);
|
||||
await useValidate(schema, req, res);
|
||||
|
||||
const { websiteId, sessionId } = req.query;
|
||||
const { websiteId, sessionId, startAt, endAt } = req.query;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const data = await getSessionActivity(websiteId, sessionId);
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getSessionActivity(websiteId, sessionId, startDate, endDate);
|
||||
|
||||
return ok(res, data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue