1
12import { z } from "zod";
13import { FORM_QUESTION_TYPES, type FormQuestionType } from "@factory/shared";
14
15export const QuestionValidationDto = z.record(z.unknown()).optional();
16
17const baseQuestion = {
18 label: z.string().min(1).max(200),
19 description: z.string().max(500).optional(),
20 required: z.boolean().default(false),
21 propertyId: z.string().min(1).nullable().optional(),
22 validation: QuestionValidationDto,
23 placeholder: z.string().max(200).optional()
24};
25
26export const CreateQuestionDto = z.object({
27 type: z.enum(FORM_QUESTION_TYPES),
28 ...baseQuestion
29});
30export type CreateQuestionInput = z.infer<typeof CreateQuestionDto>;
31
32export const UpdateQuestionDto = z
33 .object({
34 type: z.enum(FORM_QUESTION_TYPES).optional(),
35 ...baseQuestion,
36 position: z.string().min(1).max(512).optional()
37 })
38 .refine((q) => Object.keys(q).length > 1, { message: "nothing to update" });
39export type UpdateQuestionInput = z.infer<typeof UpdateQuestionDto>;
40
41export const ReorderQuestionsDto = z
42 .object({
43
44 fromId: z.string().min(1),
45
50 toId: z.string().min(1).nullable().optional()
51 })
52 .refine((q) => q.toId === undefined || q.toId === null || q.fromId !== q.toId, {
53 message: "fromId and toId must differ"
54 });
55export type ReorderQuestionsInput = z.infer<typeof ReorderQuestionsDto>;
56
57export { FORM_QUESTION_TYPES };
58export type { FormQuestionType };
59