Converted reports and share routes.

This commit is contained in:
Mike Cao 2025-01-28 10:21:56 -08:00
parent dcac7b7c96
commit 6c9f1ad06b
23 changed files with 574 additions and 5 deletions

View file

@ -0,0 +1,46 @@
import { z } from 'zod';
import { canViewWebsite } from 'lib/auth';
import { unauthorized, json } from 'lib/response';
import { parseRequest } from 'lib/request';
import { getJourney } from 'queries';
export async function POST(request: Request) {
const schema = z.object({
websiteId: z.string().uuid(),
dateRange: z.object({
startDate: z.date(),
endDate: z.date(),
}),
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);
}