All files / shared/src/types/data feedback.ts

100% Statements 30/30
100% Branches 3/3
100% Functions 0/0
100% Lines 30/30

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 431x 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 { v4 as uuidv4 } from 'uuid';
import { z } from 'zod';
 
// Main Feedback schema
export const Feedback = z
  .object({
    id: z.uuid(),
    log_id: z.uuid(),
    score: z.number().min(0).max(1),
    feedback: z.string().optional(),
    created_at: z.iso.datetime({ offset: true }),
    updated_at: z.iso.datetime({ offset: true }),
  })
  .strict();
 
export type Feedback = z.infer<typeof Feedback>;
 
// Input schema for creating feedback
export const FeedbackCreateParams = z
  .object({
    id: z.undefined().transform(() => uuidv4()),
    log_id: z.uuid(),
    score: z.number().min(0).max(1),
    feedback: z.string().optional(),
    created_at: z.undefined().transform(() => new Date().toISOString()),
    updated_at: z.undefined().transform(() => new Date().toISOString()),
  })
  .strict();
 
export type FeedbackCreateParams = z.infer<typeof FeedbackCreateParams>;
 
// Query parameters schema
export const FeedbackQueryParams = z
  .object({
    id: z.uuid().optional(),
    log_id: z.uuid().optional(),
    limit: z.coerce.number().int().positive().optional(),
    offset: z.coerce.number().int().min(0).optional(),
  })
  .strict();
 
export type FeedbackQueryParams = z.infer<typeof FeedbackQueryParams>;