问题:
如标题
原因:
query的参数默认都是string类型的,需要进行转换
解决办法:
方法一:
export class VerificationCodeDto {
@Transform(numberTransformer)
@IsNumber()
type: number;
mail: string;
}
export function numberTransformer(params: TransformFnParams) {
const { value } = params;
return Number(value);
}
方法二:
参考:
typescript - Class transformer not converting to array of numbers - Stack Overflow
PS:
如果需要注入service可以参考nestjs - Class-Validator (Node.js) Get another property value within custom validation - Stack Overflow