Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Fall back to the default page size on invalid pageSize params

Luke Vellac2a2b047ee5b
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/events/schema.ts b/apps/web/src/app/[locale]/(space)/(dashboard)/events/schema.ts
index dfa4d3320..c00ccd2bf 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/events/schema.ts
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/events/schema.ts
@@ -7,13 +7,10 @@ export const pageSchema = z.coerce.number().int().min(1).catch(1);
export const pageSizeSchema = z.coerce
.number()
- .optional()
- .transform((val) => {
- if (!val) return DEFAULT_PAGE_SIZE;
- return Number.isNaN(val) || val < 1
- ? DEFAULT_PAGE_SIZE
- : Math.min(val, 100);
- });
+ .int()
+ .min(1)
+ .transform((val) => Math.min(val, 100))
+ .catch(DEFAULT_PAGE_SIZE);
export const querySchema = z
.string()
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/schema.ts b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/schema.ts
index 024ed7725..5ab2c65fb 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/schema.ts
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/schema.ts
@@ -17,13 +17,10 @@ export const statusSchema = pollStatusSchema
export const pageSizeSchema = z.coerce
.number()
- .optional()
- .transform((val) => {
- if (!val) return DEFAULT_PAGE_SIZE;
- return Number.isNaN(val) || val < 1
- ? DEFAULT_PAGE_SIZE
- : Math.min(val, 100);
- });
+ .int()
+ .min(1)
+ .transform((val) => Math.min(val, 100))
+ .catch(DEFAULT_PAGE_SIZE);
export const memberSchema = z
.string()