From 992bdc0b543d2b305b293a8ae9dcc2f0ae8d132c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Tue, 7 Feb 2023 17:20:21 -0700 Subject: [PATCH] Fixes paginated endpoints (#234) - Passing an invalid number or 0 was causing trouble --- lib/helpers/withPagination.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/helpers/withPagination.ts b/lib/helpers/withPagination.ts index 8a78b03c2b..1f1bd397be 100644 --- a/lib/helpers/withPagination.ts +++ b/lib/helpers/withPagination.ts @@ -2,16 +2,8 @@ import { NextMiddleware } from "next-api-middleware"; import z from "zod"; const withPage = z.object({ - page: z - .string() - .optional() - .default("1") - .transform((n) => parseInt(n)), - take: z - .string() - .optional() - .default("10") - .transform((n) => parseInt(n)), + page: z.coerce.number().min(1).optional().default(1), + take: z.coerce.number().min(1).optional().default(10), }); export const withPagination: NextMiddleware = async (req, _, next) => {