2022-03-25 19:17:37 +00:00
|
|
|
import { withValidation } from "next-validations";
|
|
|
|
import { z } from "zod";
|
|
|
|
|
|
|
|
// Extracted out as utility function so can be reused
|
|
|
|
// at different endpoints that require this validation.
|
|
|
|
const schemaQueryId = z
|
|
|
|
.object({
|
|
|
|
// since nextjs parses query params as strings,
|
|
|
|
// we need to cast them to numbers using z.transform() and parseInt()
|
2022-03-25 22:26:22 +00:00
|
|
|
id: z.string()
|
2022-03-25 19:17:37 +00:00
|
|
|
})
|
|
|
|
.strict();
|
|
|
|
|
|
|
|
const withValidQueryIdString = withValidation({
|
|
|
|
schema: schemaQueryId,
|
|
|
|
type: "Zod",
|
|
|
|
mode: "query",
|
|
|
|
});
|
|
|
|
|
|
|
|
export { schemaQueryId, withValidQueryIdString };
|