All files / lib/validations sample.ts

100% Statements 36/36
100% Branches 0/0
100% Functions 0/0
100% Lines 36/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 651x         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x             1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x         1x         1x 1x 1x         1x 1x 1x 1x 1x 1x              
import { z } from 'zod';
 
/**
 * Sample types enum
 */
export const sampleTypeEnum = z.enum([
  'image',
  'video',
  'github',
  'dribbble',
  'behance',
  'url',
  'pdf',
  'other',
]);
 
export type SampleType = z.infer<typeof sampleTypeEnum>;
 
/**
 * Create sample schema
 */
export const createSampleSchema = z.object({
  type: sampleTypeEnum,
  title: z
    .string()
    .min(2, 'Title must be at least 2 characters')
    .max(100, 'Title must be at most 100 characters'),
  description: z
    .string()
    .max(500, 'Description must be at most 500 characters')
    .optional()
    .nullable(),
  url: z.string().url('Please enter a valid URL'),
  thumbnail_url: z.string().url('Please enter a valid thumbnail URL').optional().nullable(),
  display_order: z.number().int().min(0).default(0),
});
 
/**
 * Update sample schema (partial)
 */
export const updateSampleSchema = createSampleSchema.partial();
 
/**
 * Reorder samples schema
 */
export const reorderSamplesSchema = z.object({
  sample_ids: z.array(z.string().uuid()).min(1, 'At least one sample ID required'),
});
 
/**
 * Sample with ID (for responses)
 */
export const sampleSchema = createSampleSchema.extend({
  id: z.string().uuid(),
  profile_id: z.string().uuid(),
  created_at: z.string().datetime(),
  updated_at: z.string().datetime(),
});
 
// Type exports
export type CreateSampleInput = z.infer<typeof createSampleSchema>;
export type UpdateSampleInput = z.infer<typeof updateSampleSchema>;
export type ReorderSamplesInput = z.infer<typeof reorderSamplesSchema>;
export type Sample = z.infer<typeof sampleSchema>;