Created
August 16, 2021 07:15
-
-
Save bravo-kernel/cff5a2404883611817339bdf42c6a437 to your computer and use it in GitHub Desktop.
Blitzjs validations example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { z } from "zod" | |
const id = z.number().int() | |
const Project = z.object({ | |
id: id, | |
name: z.string(), | |
description: z.string().optional().nullable(), | |
customerId: z.number().int(), | |
}) | |
export const GetProjectValidation = z.object({ | |
id: id.optional().refine(Boolean, "Required"), // This accepts type of undefined, but is required at runtime | |
}) | |
export const CreateProjectValidation = Project.pick({ | |
name: true, | |
description: true, | |
customerId: true, | |
}) | |
export const UpdateProjectValidation = Project.pick({ | |
id: true, | |
name: true, | |
description: true, | |
customerId: true, | |
}) | |
export const DeleteProjectValidation = Project.pick({ | |
id: true, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment