import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { IsString, IsNotEmpty, IsOptional, IsInt, IsIn, IsEmail, IsMobilePhone } from 'class-validator'; import { Transform } from 'class-transformer'; export class RegisterDto { @ApiProperty({ description: '用户名' }) @IsString() @IsNotEmpty({ message: '用户名不能为空' }) username: string; @ApiProperty({ description: '手机号' }) @IsString() @IsNotEmpty({ message: '手机号不能为空' }) @IsMobilePhone('zh-CN', {}, { message: '手机号格式不正确' }) mobile: string; @ApiProperty({ description: '密码' }) @IsString() @IsNotEmpty({ message: '密码不能为空' }) password: string; @ApiProperty({ description: '确认密码' }) @IsString() @IsNotEmpty({ message: '确认密码不能为空' }) confirmPassword: string; @ApiPropertyOptional({ description: '昵称' }) @IsOptional() @IsString() nickname?: string; @ApiPropertyOptional({ description: '邮箱' }) @IsOptional() @IsEmail({}, { message: '邮箱格式不正确' }) email?: string; @ApiPropertyOptional({ description: '站点ID' }) @IsOptional() @IsInt() @Transform(({ value }) => parseInt(value)) siteId?: number; @ApiPropertyOptional({ description: '推广会员ID' }) @IsOptional() @IsInt() @Transform(({ value }) => parseInt(value)) pid?: number; @ApiPropertyOptional({ description: '性别:1男 2女 0未知', default: 0 }) @IsOptional() @IsIn([0, 1, 2]) @Transform(({ value }) => parseInt(value)) sex?: number = 0; @ApiPropertyOptional({ description: '注册类型:username用户名 mobile手机号 email邮箱', default: 'mobile' }) @IsOptional() @IsIn(['username', 'mobile', 'email']) regType?: string = 'mobile'; @ApiPropertyOptional({ description: '短信验证码' }) @IsOptional() @IsString() smsCode?: string; @ApiPropertyOptional({ description: '邮箱验证码' }) @IsOptional() @IsString() emailCode?: string; @ApiPropertyOptional({ description: '图形验证码' }) @IsOptional() @IsString() captcha?: string; @ApiPropertyOptional({ description: '验证码key' }) @IsOptional() @IsString() captchaKey?: string; }