Module 05 ⭐⭐ Moyen ~2h

✅ Systùme de Formulaires Dynamiques

Créer une API de formulaires dynamiques avec validation stricte, DTOs imbriqués, pipes personnalisés et sérialisation des réponses.

🔧 DTOs Ă  crĂ©er

// Champ de formulaire
export class FormFieldDto {
  @IsString() @IsNotEmpty() name: string;
  @IsEnum(['text', 'email', 'number', 'date', 'select', 'checkbox']) type: string;
  @IsString() @IsNotEmpty() label: string;
  @IsBoolean() required: boolean;
  @IsOptional() @IsArray() @IsString({ each: true }) options?: string[]; // Pour 'select'
  @IsOptional() @Min(0) minLength?: number;
  @IsOptional() @Max(10000) maxLength?: number;
}

// Formulaire complet
export class CreateFormDto {
  @IsString() @MinLength(3) @MaxLength(100) title: string;
  @IsOptional() @IsString() @MaxLength(500) description?: string;
  @IsArray() @ArrayMinSize(1) @ValidateNested({ each: true }) @Type(() => FormFieldDto)
  fields: FormFieldDto[];
  @IsBoolean() isPublic: boolean;
  @IsOptional() @IsDateString() expiresAt?: string;
}

// Réponse à un formulaire
export class SubmitFormDto {
  @IsObject() @IsNotEmpty() responses: Record<string, any>;
}

✅ FonctionnalitĂ©s

← Cours ✏ Exercices 🧠 QCM NS05 Module 06 →