This commit is contained in:
Agusti Fernandez Pardo committed 2022-03-30 14:17:55 +02:00
1 parent 39ae2aed37
commit 1de7bc4146
126 files changed
+1240 -992

No files matched your search

@@ -1,15 +1,12 @@
import { withValidation } from "next-validations";
import { z } from "zod";
import { baseApiParams } from "./baseApiParams";
// Extracted out as utility function so can be reused
// at different endpoints that require this validation.
const schemaQueryIdParseInt = z
.object({
// since we added apiKey as query param this is required by next-validations helper
// for query params to work properly and not fail.
apiKey: z.string().cuid(),
// since nextjs parses query params as strings,
// we need to cast them to numbers using z.transform() and parseInt()
export const schemaQueryIdParseInt = baseApiParams
.extend({
id: z
.string()
.regex(/^\d+$/)
@@ -17,10 +14,8 @@ const schemaQueryIdParseInt = z
})
.strict();
const withValidQueryIdTransformParseInt = withValidation({
export const withValidQueryIdTransformParseInt = withValidation({
schema: schemaQueryIdParseInt,
type: "Zod",
mode: "query",
});
export { schemaQueryIdParseInt, withValidQueryIdTransformParseInt };