diff --git a/src/lib/validators/brochures.ts b/src/lib/validators/brochures.ts index a30acd2f..577ab70c 100644 --- a/src/lib/validators/brochures.ts +++ b/src/lib/validators/brochures.ts @@ -1,16 +1,19 @@ import { z } from 'zod'; +import { createInsertSchema, createUpdateSchema } from 'drizzle-zod'; -export const createBrochureSchema = z.object({ - label: z.string().trim().min(1).max(120), - description: z.string().max(500).optional().nullable(), - isDefault: z.boolean().optional(), -}); +import { brochures } from '@/lib/db/schema/brochures'; -export const updateBrochureSchema = z.object({ - label: z.string().trim().min(1).max(120).optional(), - description: z.string().max(500).optional().nullable(), - isDefault: z.boolean().optional(), -}); +// Derived from the Drizzle table — adding a column to `brochures` +// auto-includes it here. Refinements override per-field. +export const createBrochureSchema = createInsertSchema(brochures, { + label: (s) => s.trim().min(1).max(120), + description: (s) => s.max(500), +}).pick({ label: true, description: true, isDefault: true }); + +export const updateBrochureSchema = createUpdateSchema(brochures, { + label: (s) => s.trim().min(1).max(120), + description: (s) => s.max(500), +}).pick({ label: true, description: true, isDefault: true }); export const registerBrochureVersionSchema = z.object({ storageKey: z diff --git a/src/lib/validators/tags.ts b/src/lib/validators/tags.ts index 378018ca..b954633d 100644 --- a/src/lib/validators/tags.ts +++ b/src/lib/validators/tags.ts @@ -1,13 +1,15 @@ import { z } from 'zod'; +import { createInsertSchema } from 'drizzle-zod'; -export const createTagSchema = z.object({ - name: z.string().min(1).max(50), - color: z - .string() - .regex(/^#[0-9A-Fa-f]{6}$/, 'Color must be a valid hex color (e.g. #6B7280)') - .optional() - .default('#6B7280'), -}); +import { tags } from '@/lib/db/schema/system'; + +// Derive the schema from the Drizzle table — adding a column to `tags` +// auto-includes it here; omitting / refining is per-field. Eliminates +// the validator-drift class of bugs the audit flagged. +export const createTagSchema = createInsertSchema(tags, { + name: (s) => s.min(1).max(50), + color: (s) => s.regex(/^#[0-9A-Fa-f]{6}$/, 'Color must be a valid hex color (e.g. #6B7280)'), +}).pick({ name: true, color: true }); export const updateTagSchema = createTagSchema.partial();