72 lines
1.5 KiB
TypeScript
72 lines
1.5 KiB
TypeScript
import { Transform } from 'class-transformer';
|
|
import {
|
|
IsEmail,
|
|
IsOptional,
|
|
IsString,
|
|
Matches,
|
|
MaxLength,
|
|
MinLength,
|
|
} from 'class-validator';
|
|
|
|
const optionalText = ({ value }: { value: unknown }) =>
|
|
typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
|
|
export class UpdateUserDto {
|
|
@Transform(({ value }) =>
|
|
typeof value === 'string' ? value.trim().toLowerCase() : value,
|
|
)
|
|
@IsOptional()
|
|
@IsString()
|
|
@MinLength(3)
|
|
@MaxLength(80)
|
|
@Matches(/^[a-zA-Z0-9._-]+$/)
|
|
username?: string;
|
|
|
|
@Transform(({ value }) =>
|
|
typeof value === 'string' && value.trim() ? value.trim().toLowerCase() : null,
|
|
)
|
|
@IsOptional()
|
|
@IsEmail()
|
|
@MaxLength(320)
|
|
email?: string | null;
|
|
|
|
@Transform(({ value }) =>
|
|
typeof value === 'string' && value.trim() ? value.replace(/\D/g, '') : null,
|
|
)
|
|
@IsOptional()
|
|
@Matches(/^\d{7,11}$/)
|
|
dni?: string | null;
|
|
|
|
@Transform(optionalText)
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(40)
|
|
phone?: string | null;
|
|
|
|
@Transform(optionalText)
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(160)
|
|
jobTitle?: string | null;
|
|
|
|
@Transform(optionalText)
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(80)
|
|
employeeNumber?: string | null;
|
|
|
|
@Transform(({ value }) => (typeof value === 'string' ? value.trim() : value))
|
|
@IsOptional()
|
|
@IsString()
|
|
@MinLength(1)
|
|
@MaxLength(120)
|
|
firstName?: string;
|
|
|
|
@Transform(({ value }) => (typeof value === 'string' ? value.trim() : value))
|
|
@IsOptional()
|
|
@IsString()
|
|
@MinLength(1)
|
|
@MaxLength(120)
|
|
lastName?: string;
|
|
}
|