All files / src/schemas flyer.schemas.ts

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

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                1x                                           1x      
// src/schemas/flyer.schemas.ts
import { z } from 'zod';
import { httpUrl, requiredString } from '../utils/zodUtils';
 
/**
 * Zod schema for FlyerInsert type with strict URL validation.
 * Ensures image_url and icon_url match database constraints (^https?://.*).
 */
export const flyerInsertSchema = z.object({
  file_name: requiredString('File name is required'),
  image_url: httpUrl('Flyer image URL must be a valid HTTP or HTTPS URL'),
  icon_url: httpUrl('Flyer icon URL must be a valid HTTP or HTTPS URL'),
  checksum: z
    .string()
    .length(64, 'Checksum must be 64 characters')
    .regex(/^[a-f0-9]+$/, 'Checksum must be a valid hexadecimal string')
    .nullable(),
  store_name: requiredString('Store name is required'),
  valid_from: z.string().datetime().nullable(),
  valid_to: z.string().datetime().nullable(),
  store_address: z.string().nullable(),
  status: z.enum(['processed', 'needs_review', 'archived']),
  item_count: z.number().int().nonnegative('Item count must be non-negative'),
  uploaded_by: z.string().uuid().nullable().optional(),
});
 
/**
 * Zod schema for FlyerDbInsert type with URL validation.
 * Same as flyerInsertSchema but uses store_id instead of store_name.
 */
export const flyerDbInsertSchema = flyerInsertSchema.omit({ store_name: true }).extend({
  store_id: z.number().int().positive('Store ID must be a positive integer'),
});