extracting out schemaQuery validation to lib, extracting out delete/edit to it's own files for clarity

This commit is contained in:
Agusti Fernandez Pardo
2022-03-25 00:04:07 +01:00
parent e4d9f7bc7d
commit 737a8897ba
7 changed files with 135 additions and 33 deletions
@@ -0,0 +1,15 @@
import { z } from "zod";
// Extracted out as utility function so can be reused
// at different endpoints that require this validation.
const schema = z
.object({
// since nextjs parses query params as strings,
// we need to cast them to numbers using z.transform() and parseInt()
id: z
.string()
.regex(/^\d+$/)
.transform((id) => parseInt(id)),
})
.strict();
export default schema;