mirror of
https://github.com/umami-software/umami.git
synced 2026-02-15 01:55:36 +01:00
Converted reports and share routes.
This commit is contained in:
parent
dcac7b7c96
commit
6c9f1ad06b
23 changed files with 574 additions and 5 deletions
53
src/app/api/reports/goals/route.ts
Normal file
53
src/app/api/reports/goals/route.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { z } from 'zod';
|
||||
import { canViewWebsite } from 'lib/auth';
|
||||
import { unauthorized, json } from 'lib/response';
|
||||
import { parseRequest } from 'lib/request';
|
||||
import { getGoals } from 'queries/analytics/reports/getGoals';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
websiteId: z.string().uuid(),
|
||||
dateRange: z.object({
|
||||
startDate: z.date(),
|
||||
endDate: z.date(),
|
||||
}),
|
||||
goals: z
|
||||
.array(
|
||||
z.object({
|
||||
type: z.string().regex(/url|event|event-data/),
|
||||
value: z.string(),
|
||||
goal: z.number(),
|
||||
operator: z
|
||||
.string()
|
||||
.regex(/count|sum|average/)
|
||||
.refine(data => data['type'] === 'event-data'),
|
||||
property: z.string().refine(data => data['type'] === 'event-data'),
|
||||
}),
|
||||
)
|
||||
.min(1),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const {
|
||||
websiteId,
|
||||
dateRange: { startDate, endDate },
|
||||
goals,
|
||||
} = body;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const data = await getGoals(websiteId, {
|
||||
startDate: new Date(startDate),
|
||||
endDate: new Date(endDate),
|
||||
goals,
|
||||
});
|
||||
|
||||
return json(data);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue