import { MatchField } from '@/common/decorators/match-field.decorator'; import { ApiProperty } from '@nestjs/swagger'; import { IsOptional, IsString, Matches, MaxLength, MinLength, ValidateIf, } from 'class-validator'; import { i18nValidationMessage as t } from 'nestjs-i18n'; export class UpdateProfileDTO { @ApiProperty({ type: 'string', description: `User's Firstname`, example: 'Radmehr', required: false, }) @IsString() @IsOptional() @MinLength(3, { message: t('validation.minLengthField', { field: '$t(users.fields.firstName)', min: 3, }), }) @MaxLength(96, { message: t('validation.maxLengthField', { field: '$t(users.fields.firstName)', max: 96, }), }) firstName?: string; @ApiProperty({ type: 'string', description: `User's Lastname`, example: 'Tarnas', required: false, }) @IsString() @IsOptional() @MinLength(3, { message: t('validation.minLengthField', { field: '$t(users.fields.lastName)', min: 3, }), }) @MaxLength(96, { message: t('validation.maxLengthField', { field: '$t(users.fields.lastName)', max: 96, }), }) lastName?: string; @ApiProperty({ type: 'string', description: 'Password for User Account', example: 'Password1@', required: false, }) @IsString() @IsOptional() @MinLength(8, { message: t('validation.minLengthField', { field: '$t(users.fields.password)', min: 8, }), }) @MaxLength(96, { message: t('validation.maxLengthField', { field: '$t(users.fields.password)', max: 96, }), }) @Matches(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[^A-Za-z\d]).{8,}$/, { message: t('users.errors.passwordPattern'), }) password?: string; @ApiProperty({ type: 'string', description: 'Confirm Password of User Account (Should match Password)', example: 'Password1@', required: false, }) // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access @ValidateIf((o) => o.password !== undefined) @IsOptional() @MatchField('password') confirmPassword?: string; }