mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 22:27:16 +01:00
26 lines
829 B
TypeScript
26 lines
829 B
TypeScript
import { canViewWebsite } from '@/validations';
|
|
import { unauthorized, json } from '@/lib/response';
|
|
import { getQueryFilters, parseRequest, setWebsiteDate } from '@/lib/request';
|
|
import { getGoal, GoalParameters } from '@/queries/sql/reports/getGoal';
|
|
import { reportResultSchema } from '@/lib/schema';
|
|
|
|
export async function POST(request: Request) {
|
|
const { auth, body, error } = await parseRequest(request, reportResultSchema);
|
|
|
|
if (error) {
|
|
return error();
|
|
}
|
|
|
|
const { websiteId } = body;
|
|
|
|
if (!(await canViewWebsite(auth, websiteId))) {
|
|
return unauthorized();
|
|
}
|
|
|
|
const parameters = await setWebsiteDate(websiteId, body.parameters);
|
|
const filters = await getQueryFilters(body.filters, websiteId);
|
|
|
|
const data = await getGoal(websiteId, parameters as GoalParameters, filters);
|
|
|
|
return json(data);
|
|
}
|