Refactor filter handling for queries.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { getGoal } from '@/queries/sql/reports/getGoal';
|
||||
import { reportResultSchema } from '@/lib/schema';
|
||||
|
||||
@@ -15,21 +15,22 @@ export async function POST(request: Request) {
|
||||
websiteId,
|
||||
dateRange: { startDate, endDate },
|
||||
parameters: { type, value, property, operator },
|
||||
...filters
|
||||
} = body;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const filters = await getQueryFilters(body.filters);
|
||||
|
||||
const data = await getGoal(websiteId, {
|
||||
...filters,
|
||||
startDate: new Date(startDate),
|
||||
endDate: new Date(endDate),
|
||||
type,
|
||||
value,
|
||||
property,
|
||||
operator,
|
||||
filters,
|
||||
});
|
||||
|
||||
return json(data);
|
||||
|
||||
Reference in New Issue
Block a user