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:
hailin 2026-03-10 20:04:49 -07:00
parent 149cf7ea77
commit 936c3e89c1
1 changed files with 17 additions and 2 deletions

View File

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