mirror of
https://github.com/umami-software/umami.git
synced 2026-02-14 01:25:37 +01:00
Updated zod validation on date range.
This commit is contained in:
parent
6c793325e2
commit
fb6fd293fb
10 changed files with 36 additions and 31 deletions
|
|
@ -23,6 +23,25 @@ export const dateRangeParams = {
|
|||
compare: z.enum(['prev', 'yoy']).optional(),
|
||||
};
|
||||
|
||||
export function withDateRange<T extends z.ZodRawShape>(shape?: T) {
|
||||
return z
|
||||
.object({
|
||||
...dateRangeParams,
|
||||
...shape,
|
||||
})
|
||||
.superRefine((data: Record<string, unknown>, ctx) => {
|
||||
const hasTimestamps = data.startAt != null && data.endAt != null;
|
||||
const hasDates = data.startDate != null && data.endDate != null;
|
||||
|
||||
if (!hasTimestamps && !hasDates) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Either startAt+endAt or startDate+endDate must be provided',
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const filterParams = {
|
||||
path: z.string().optional(),
|
||||
referrer: z.string().optional(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue