Fixes paginated endpoints (#234)

- Passing an invalid number or 0 was causing trouble
pull/9078/head
Omar López 2023-02-07 17:20:21 -07:00 committed by GitHub
parent 279c3da21f
commit 992bdc0b54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 10 deletions

View File

@ -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) => {