Skip to content

Instantly share code, notes, and snippets.

@bravo-kernel
Created August 16, 2021 07:15
Show Gist options
  • Save bravo-kernel/cff5a2404883611817339bdf42c6a437 to your computer and use it in GitHub Desktop.
Save bravo-kernel/cff5a2404883611817339bdf42c6a437 to your computer and use it in GitHub Desktop.
Blitzjs validations example
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