Files
backend/src/profile-fields/dto/create-field.dto.ts
pradeepkumar 710803a3ec fix
2026-01-24 03:33:54 +05:30

114 lines
2.8 KiB
TypeScript

import {
IsString,
IsOptional,
IsBoolean,
IsInt,
IsUUID,
IsEnum,
IsObject,
IsArray,
MinLength,
MaxLength,
ValidateNested,
} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { FieldType } from '@prisma/client';
export class FieldOptionDto {
@ApiProperty({ description: 'Option value' })
@IsString()
value: string;
@ApiProperty({ description: 'Option display label' })
@IsString()
label: string;
@ApiPropertyOptional({ description: 'Sort order for this option' })
@IsOptional()
@IsInt()
sortOrder?: number;
}
export class RangeConfigDto {
@ApiProperty({ description: 'Minimum value' })
min: number;
@ApiProperty({ description: 'Maximum value' })
max: number;
@ApiPropertyOptional({ description: 'Step increment', default: 1 })
@IsOptional()
step?: number;
}
export class CreateFieldDto {
@ApiProperty({ description: 'Section ID this field belongs to' })
@IsUUID()
sectionId: string;
@ApiProperty({ description: 'Field name', example: 'Years in Business' })
@IsString()
@MinLength(2)
@MaxLength(100)
name: string;
@ApiProperty({ description: 'Field type', enum: FieldType })
@IsEnum(FieldType)
fieldType: FieldType;
@ApiPropertyOptional({ description: 'Help text for the field' })
@IsOptional()
@IsString()
@MaxLength(500)
description?: string;
@ApiPropertyOptional({ description: 'Placeholder text' })
@IsOptional()
@IsString()
@MaxLength(200)
placeholder?: string;
@ApiPropertyOptional({ description: 'Default value (JSON string for complex types)' })
@IsOptional()
@IsString()
defaultValue?: string;
@ApiPropertyOptional({ description: 'Sort order within the section', default: 0 })
@IsOptional()
@IsInt()
sortOrder?: number;
@ApiPropertyOptional({ description: 'Whether this field is active', default: true })
@IsOptional()
@IsBoolean()
isActive?: boolean;
@ApiPropertyOptional({ description: 'Whether this field is required', default: false })
@IsOptional()
@IsBoolean()
isRequired?: boolean;
@ApiPropertyOptional({ description: 'Validation rules (JSON object)' })
@IsOptional()
@IsObject()
validation?: Record<string, any>;
@ApiPropertyOptional({ description: 'Options for SELECT, RADIO, MULTI_SELECT, CHECKBOX_GROUP', type: [FieldOptionDto] })
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => FieldOptionDto)
options?: FieldOptionDto[];
@ApiPropertyOptional({ description: 'Configuration for RANGE fields', type: RangeConfigDto })
@IsOptional()
@IsObject()
rangeConfig?: RangeConfigDto;
@ApiPropertyOptional({ description: 'UI configuration (JSON object)' })
@IsOptional()
@IsObject()
uiConfig?: Record<string, any>;
}