Skip to content

Commit

Permalink
Fixes paginated endpoints (#234)
Browse files Browse the repository at this point in the history
- Passing an invalid number or 0 was causing trouble
  • Loading branch information
zomars committed Feb 8, 2023
1 parent 279c3da commit 992bdc0
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions lib/helpers/withPagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 992bdc0

Please sign in to comment.