mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 12:47:13 +01:00
34 lines
836 B
TypeScript
34 lines
836 B
TypeScript
import { canViewWebsite } from '@/lib/auth';
|
|
import { parseRequest } from '@/lib/request';
|
|
import { json, unauthorized } from '@/lib/response';
|
|
import { reportResultSchema } from '@/lib/schema';
|
|
import { getAttribution } from '@/queries/sql/reports/getAttribution';
|
|
|
|
export async function POST(request: Request) {
|
|
const { auth, body, error } = await parseRequest(request, reportResultSchema);
|
|
|
|
if (error) {
|
|
return error();
|
|
}
|
|
|
|
const {
|
|
websiteId,
|
|
dateRange: { startDate, endDate },
|
|
parameters: { model, type, step, currency },
|
|
} = body;
|
|
|
|
if (!(await canViewWebsite(auth, websiteId))) {
|
|
return unauthorized();
|
|
}
|
|
|
|
const data = await getAttribution(websiteId, {
|
|
startDate: new Date(startDate),
|
|
endDate: new Date(endDate),
|
|
model,
|
|
type,
|
|
step,
|
|
currency,
|
|
});
|
|
|
|
return json(data);
|
|
}
|