Breakdown report.

This commit is contained in:
Mike Cao 2025-06-10 20:59:27 -07:00
parent 79ea9974b7
commit e3cc19638c
21 changed files with 495 additions and 456 deletions

View file

@ -0,0 +1,30 @@
import { canViewWebsite } from '@/lib/auth';
import { unauthorized, json } from '@/lib/response';
import { parseRequest } from '@/lib/request';
import { getBreakdown } from '@/queries';
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,
dateRange: { startDate, endDate },
parameters: { fields },
} = body;
if (!(await canViewWebsite(auth, websiteId))) {
return unauthorized();
}
const data = await getBreakdown(websiteId, fields, {
startDate: new Date(startDate),
endDate: new Date(endDate),
});
return json(data);
}