mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 23:27:12 +01:00
43 lines
925 B
TypeScript
43 lines
925 B
TypeScript
import { z } from 'zod';
|
|
import { canViewWebsite } from 'lib/auth';
|
|
import { unauthorized, json } from 'lib/response';
|
|
import { parseRequest } from 'lib/request';
|
|
import { getJourney } from 'queries';
|
|
import { reportParms } from 'lib/schema';
|
|
|
|
export async function POST(request: Request) {
|
|
const schema = z.object({
|
|
...reportParms,
|
|
steps: z.number().min(3).max(7),
|
|
startStep: z.string(),
|
|
endStep: z.string(),
|
|
});
|
|
|
|
const { auth, body, error } = await parseRequest(request, schema);
|
|
|
|
if (error) {
|
|
return error();
|
|
}
|
|
|
|
const {
|
|
websiteId,
|
|
dateRange: { startDate, endDate },
|
|
steps,
|
|
startStep,
|
|
endStep,
|
|
} = body;
|
|
|
|
if (!(await canViewWebsite(auth, websiteId))) {
|
|
return unauthorized();
|
|
}
|
|
|
|
const data = await getJourney(websiteId, {
|
|
startDate: new Date(startDate),
|
|
endDate: new Date(endDate),
|
|
steps,
|
|
startStep,
|
|
endStep,
|
|
});
|
|
|
|
return json(data);
|
|
}
|