fix: add optional to pagination query's
parent
c8829fc08b
commit
6971ba249f
|
@ -5,22 +5,24 @@ const withPage = z.object({
|
|||
page: z
|
||||
.string()
|
||||
.min(1)
|
||||
.optional()
|
||||
.default("1")
|
||||
.transform((n) => parseInt(n)),
|
||||
take: z
|
||||
.string()
|
||||
.min(10)
|
||||
.max(100)
|
||||
.optional()
|
||||
.default("10")
|
||||
.transform((n) => parseInt(n)),
|
||||
});
|
||||
|
||||
export const withPagination: NextMiddleware = async (req, _, next) => {
|
||||
const { page, take } = withPage.parse(req.query);
|
||||
const skip = page * take;
|
||||
const skip = page * take || 0;
|
||||
req.pagination = {
|
||||
take: take || 10,
|
||||
skip: skip || 0,
|
||||
take,
|
||||
skip,
|
||||
};
|
||||
await next();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue