fix(auth): SMS controller DTO 缺少 class-validator 装饰器导致发送失败
全局 ValidationPipe 开启了 whitelist + forbidNonWhitelisted, SendSmsDto/VerifySmsDto 没有装饰器导致 phone/type 被当成非法属性拒绝。 补齐 @IsString/@IsNotEmpty/@Matches/@IsEnum 装饰器。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
149cf7ea77
commit
936c3e89c1
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in New Issue