cal.pub0.org/lib/validations/shared/queryIdTransformParseInt.ts

22 lines
542 B
TypeScript
Raw Normal View History

2022-03-25 05:54:57 +00:00
import { withValidation } from "next-validations";
import { z } from "zod";
2022-03-30 12:17:55 +00:00
import { baseApiParams } from "./baseApiParams";
// Extracted out as utility function so can be reused
// at different endpoints that require this validation.
2022-03-30 12:17:55 +00:00
export const schemaQueryIdParseInt = baseApiParams
.extend({
id: z
.string()
.regex(/^\d+$/)
.transform((id) => parseInt(id)),
})
.strict();
2022-03-25 05:54:57 +00:00
2022-03-30 12:17:55 +00:00
export const withValidQueryIdTransformParseInt = withValidation({
schema: schemaQueryIdParseInt,
2022-03-25 05:54:57 +00:00
type: "Zod",
mode: "query",
});