Fixed report validations.

This commit is contained in:
Mike Cao 2025-02-01 19:55:53 -08:00
parent 530d6fb323
commit 6ab7746b7d
2 changed files with 19 additions and 10 deletions

View file

@ -10,15 +10,22 @@ export async function POST(request: Request) {
...reportParms, ...reportParms,
goals: z goals: z
.array( .array(
z.object({ z
.object({
type: z.string().regex(/url|event|event-data/), type: z.string().regex(/url|event|event-data/),
value: z.string(), value: z.string(),
goal: z.number(), goal: z.coerce.number(),
operator: z operator: z
.string() .string()
.regex(/count|sum|average/) .regex(/count|sum|average/)
.refine(data => data['type'] === 'event-data'), .optional(),
property: z.string().refine(data => data['type'] === 'event-data'), property: z.string().optional(),
})
.refine(data => {
if (data['type'] === 'event-data') {
return data['operator'] && data['property'];
}
return true;
}), }),
) )
.min(1), .min(1),

View file

@ -8,6 +8,8 @@ import { getReports, createReport } from 'queries';
export async function GET(request: Request) { export async function GET(request: Request) {
const schema = z.object({ const schema = z.object({
websiteId: z.string().uuid().optional(),
teamId: z.string().uuid().optional(),
...pagingParams, ...pagingParams,
}); });