import { Transform } from 'class-transformer'; import { IsBoolean, IsEnum, IsInt, IsOptional, IsString, Max, MaxLength, Min, MinLength, ValidateIf, } from 'class-validator'; import { SmtpSecurityMode } from '../../../database/entities'; export enum UserSmtpMode { SYSTEM = 'SYSTEM', CUSTOM = 'CUSTOM', } const trimmed = ({ value }: { value: unknown }) => typeof value === 'string' ? value.trim() : value; export class UpdateUserSmtpSettingsDto { @IsEnum(UserSmtpMode) mode!: UserSmtpMode; @ValidateIf((dto: UpdateUserSmtpSettingsDto) => dto.mode === UserSmtpMode.CUSTOM) @Transform(trimmed) @IsString() @MinLength(1) @MaxLength(255) host?: string; @ValidateIf((dto: UpdateUserSmtpSettingsDto) => dto.mode === UserSmtpMode.CUSTOM) @IsInt() @Min(1) @Max(65535) port?: number; @ValidateIf((dto: UpdateUserSmtpSettingsDto) => dto.mode === UserSmtpMode.CUSTOM) @IsEnum(SmtpSecurityMode) securityMode?: SmtpSecurityMode; @IsOptional() @Transform(trimmed) @IsString() @MaxLength(255) username?: string | null; @IsOptional() @IsString() @MaxLength(512) password?: string | null; @IsOptional() @Transform(trimmed) @IsString() @MaxLength(200) fromName?: string | null; @IsOptional() @IsBoolean() enabled = true; }