diff --git a/backend/services/auth-service/src/api/controllers/sms.controller.ts b/backend/services/auth-service/src/api/controllers/sms.controller.ts index 7fa2f668..3e082b38 100644 --- a/backend/services/auth-service/src/api/controllers/sms.controller.ts +++ b/backend/services/auth-service/src/api/controllers/sms.controller.ts @@ -7,18 +7,33 @@ import { UseGuards, } from '@nestjs/common'; import { ThrottlerGuard } from '@nestjs/throttler'; +import { IsString, IsNotEmpty, IsEnum, Matches } from 'class-validator'; import { SmsService } from '@/application/services'; import { SmsVerificationType } from '@/domain'; class SendSmsDto { + @IsString() + @IsNotEmpty({ message: '手机号不能为空' }) + @Matches(/^1[3-9]\d{9}$/, { message: '手机号格式不正确' }) phone: string; - type: 'REGISTER' | 'LOGIN' | 'RESET_PASSWORD' | 'CHANGE_PHONE'; + + @IsEnum(SmsVerificationType, { message: '验证码类型无效' }) + type: SmsVerificationType; } class VerifySmsDto { + @IsString() + @IsNotEmpty({ message: '手机号不能为空' }) + @Matches(/^1[3-9]\d{9}$/, { message: '手机号格式不正确' }) phone: string; + + @IsString() + @IsNotEmpty({ message: '验证码不能为空' }) + @Matches(/^\d{6}$/, { message: '验证码格式不正确' }) code: string; - type: 'REGISTER' | 'LOGIN' | 'RESET_PASSWORD' | 'CHANGE_PHONE'; + + @IsEnum(SmsVerificationType, { message: '验证码类型无效' }) + type: SmsVerificationType; } @Controller('auth/sms')