Files
CRM_Montzar/apps/api/src/lead-forms/dto.ts
T

199 lines
3.1 KiB
TypeScript
Raw Normal View History

import {
ArrayMaxSize,
IsArray,
IsBoolean,
IsIn,
IsObject,
IsOptional,
IsString,
MaxLength,
MinLength,
ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';
import { LEAD_FORM_FIELD_TYPES } from '@mento/shared';
const MAP_TO = [
'person.firstName',
'person.lastName',
'person.fullName',
'person.email',
'person.mobile',
'person.phone',
'person.position',
'deal.title',
'deal.notes',
'notes',
'custom',
] as const;
export class LeadFormFieldInputDto {
@IsOptional()
@IsString()
@MaxLength(64)
key?: string;
@IsString()
@MinLength(1)
@MaxLength(120)
label!: string;
@IsIn([...LEAD_FORM_FIELD_TYPES])
fieldType!: (typeof LEAD_FORM_FIELD_TYPES)[number];
@IsOptional()
@IsBoolean()
required?: boolean;
@IsIn(MAP_TO)
mapTo!: (typeof MAP_TO)[number];
@IsOptional()
position?: number;
@IsOptional()
@IsString()
@MaxLength(160)
placeholder?: string | null;
@IsOptional()
@IsArray()
@IsString({ each: true })
@ArrayMaxSize(40)
options?: string[];
}
export class CreateLeadFormDto {
@IsString()
@MinLength(2)
@MaxLength(120)
name!: string;
@IsOptional()
@IsString()
@MaxLength(400)
description?: string | null;
@IsOptional()
@IsBoolean()
createPerson?: boolean;
@IsOptional()
@IsBoolean()
createDeal?: boolean;
@IsOptional()
@IsString()
pipelineId?: string | null;
@IsOptional()
@IsString()
@MaxLength(80)
source?: string | null;
@IsOptional()
@IsString()
@MaxLength(500)
thankYouMessage?: string | null;
@IsOptional()
@IsString()
@MaxLength(500)
redirectUrl?: string | null;
@IsOptional()
@IsArray()
@IsString({ each: true })
@ArrayMaxSize(50)
assigneeIds?: string[];
@IsOptional()
@IsString()
@MaxLength(80)
submitLabel?: string;
@IsOptional()
@IsString()
@MaxLength(20)
submitColor?: string;
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => LeadFormFieldInputDto)
@ArrayMaxSize(40)
fields?: LeadFormFieldInputDto[];
}
export class UpdateLeadFormDto {
@IsOptional()
@IsString()
@MinLength(2)
@MaxLength(120)
name?: string;
@IsOptional()
@IsString()
@MaxLength(400)
description?: string | null;
@IsOptional()
@IsBoolean()
isActive?: boolean;
@IsOptional()
@IsBoolean()
createPerson?: boolean;
@IsOptional()
@IsBoolean()
createDeal?: boolean;
@IsOptional()
@IsString()
pipelineId?: string | null;
@IsOptional()
@IsString()
@MaxLength(80)
source?: string | null;
@IsOptional()
@IsString()
@MaxLength(500)
thankYouMessage?: string | null;
@IsOptional()
@IsString()
@MaxLength(500)
redirectUrl?: string | null;
@IsOptional()
@IsArray()
@IsString({ each: true })
@ArrayMaxSize(50)
assigneeIds?: string[];
@IsOptional()
@IsString()
@MaxLength(80)
submitLabel?: string;
@IsOptional()
@IsString()
@MaxLength(20)
submitColor?: string;
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => LeadFormFieldInputDto)
@ArrayMaxSize(40)
fields?: LeadFormFieldInputDto[];
}
export class SubmitLeadFormDto {
@IsObject()
values!: Record<string, string>;
}