mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 06:37:18 +01:00
Use getRequestDateRange in all routes.
This commit is contained in:
parent
b0023feee9
commit
5171bdaf47
21 changed files with 72 additions and 173 deletions
|
|
@ -3,7 +3,7 @@ import { json, unauthorized } from '@/lib/response';
|
|||
import { getAllUserWebsitesIncludingTeamOwner } from '@/queries/prisma/website';
|
||||
import { getEventUsage } from '@/queries/sql/events/getEventUsage';
|
||||
import { getEventDataUsage } from '@/queries/sql/events/getEventDataUsage';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { parseRequest, getRequestDateRange } from '@/lib/request';
|
||||
|
||||
export async function GET(request: Request, { params }: { params: Promise<{ userId: string }> }) {
|
||||
const schema = z.object({
|
||||
|
|
@ -22,10 +22,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ user
|
|||
}
|
||||
|
||||
const { userId } = await params;
|
||||
const { startAt, endAt } = query;
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
const websites = await getAllUserWebsitesIncludingTeamOwner(userId);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRequestDateRange, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { getEventDataEvents } from '@/queries/sql/events/getEventDataEvents';
|
||||
|
|
@ -20,15 +20,13 @@ export async function GET(
|
|||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt, event } = query;
|
||||
const { event } = query;
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataEvents(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRequestDateRange, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { getEventDataFields } from '@/queries';
|
||||
|
|
@ -20,15 +20,12 @@ export async function GET(
|
|||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt } = query;
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataFields(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRequestDateRange, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { getEventDataProperties } from '@/queries';
|
||||
|
|
@ -21,15 +21,13 @@ export async function GET(
|
|||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt, propertyName } = query;
|
||||
const { propertyName } = query;
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataProperties(websiteId, { startDate, endDate, propertyName });
|
||||
|
||||
return json(data);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRequestDateRange, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { getEventDataStats } from '@/queries';
|
||||
|
|
@ -21,15 +21,12 @@ export async function GET(
|
|||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt } = query;
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataStats(websiteId, { startDate, endDate });
|
||||
|
||||
return json(data);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRequestDateRange, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { getEventDataValues } from '@/queries';
|
||||
|
|
@ -22,15 +22,13 @@ export async function GET(
|
|||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt, eventName, propertyName } = query;
|
||||
const { eventName, propertyName } = query;
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataValues(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRequestDateRange, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { pagingParams } from '@/lib/schema';
|
||||
|
|
@ -22,15 +22,12 @@ export async function GET(
|
|||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt } = query;
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getWebsiteEvents(websiteId, { startDate, endDate }, query);
|
||||
|
||||
return json(data);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export async function GET(
|
|||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
unit: unitParam,
|
||||
unit: unitParam.optional(),
|
||||
timezone: timezoneParam,
|
||||
...filterParams,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRequestDateRange, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { getSessionDataProperties } from '@/queries';
|
||||
|
|
@ -20,16 +20,14 @@ export async function GET(
|
|||
return error();
|
||||
}
|
||||
|
||||
const { startAt, endAt, propertyName } = query;
|
||||
const { websiteId } = await params;
|
||||
const { propertyName } = query;
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getSessionDataProperties(websiteId, { startDate, endDate, propertyName });
|
||||
|
||||
return json(data);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRequestDateRange, parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { getSessionDataValues } from '@/queries';
|
||||
import { z } from 'zod';
|
||||
|
|
@ -20,16 +20,14 @@ export async function GET(
|
|||
return error();
|
||||
}
|
||||
|
||||
const { startAt, endAt, propertyName } = query;
|
||||
const { propertyName } = query;
|
||||
const { websiteId } = await params;
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getSessionDataValues(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { parseRequest, getRequestDateRange } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { getSessionActivity } from '@/queries';
|
||||
|
|
@ -20,15 +20,12 @@ export async function GET(
|
|||
}
|
||||
|
||||
const { websiteId, sessionId } = await params;
|
||||
const { startAt, endAt } = query;
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getSessionActivity(websiteId, sessionId, startDate, endDate);
|
||||
|
||||
return json(data);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRequestDateRange, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { pagingParams } from '@/lib/schema';
|
||||
|
|
@ -21,16 +21,13 @@ export async function GET(
|
|||
return error();
|
||||
}
|
||||
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRequestDateRange, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { pagingParams, timezoneParam } from '@/lib/schema';
|
||||
|
|
@ -23,15 +23,13 @@ export async function GET(
|
|||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt, timezone } = query;
|
||||
const { timezone } = query;
|
||||
const { startDate, endDate } = await getRequestDateRange(query);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getWebsiteSessionsWeekly(websiteId, { startDate, endDate, timezone });
|
||||
|
||||
return json(data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue