1
9import { z } from "zod";
10import { CreateQuestionDto, type CreateQuestionInput } from "./question.dto.js";
11
12export const CreateFormDto = z.object({
13 name: z.string().min(1).max(100),
14 slug: z
15 .string()
16 .min(2)
17 .max(50)
18 .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
19 .optional(),
20 description: z.string().max(500).optional(),
21 config: z.record(z.unknown()).optional(),
22 questions: z.array(CreateQuestionDto).max(50).optional()
23});
24export type CreateFormInput = z.infer<typeof CreateFormDto> & {
25 questions?: CreateQuestionInput[];
26};
27
28export const UpdateFormDto = z
29 .object({
30 name: z.string().min(1).max(100).optional(),
31 description: z.string().max(500).nullable().optional(),
32 status: z.enum(["DRAFT", "PUBLISHED", "CLOSED"]).optional(),
33 slug: z.string().min(2).max(50).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).optional(),
34 config: z.record(z.unknown()).optional(),
35 questions: z.array(CreateQuestionDto).max(50).optional()
36 })
37 .refine((f) => Object.keys(f).length > 0, { message: "nothing to update" });
38export type UpdateFormInput = z.infer<typeof UpdateFormDto> & {
39 questions?: CreateQuestionInput[];
40};
41