嗨!我有一个关于类验证器的问题。
我的客户将要求多个数字,我需要比较对方的价值。
我要下面的代码。
const validator: SomeValidator = new SomeValidator;
validator.first = 1000;
validator.second = 2000; // this will be greater than validator.first
validator.third = 3000; // this will be greater than validator.second
我尝试将变量输入到@Min()验证器中,如下所示
import {
我有一个用typescript编写的简单库,我将其与Rollup捆绑在一起。现在它得到了它的第一个依赖项:。尽管它是一个typescript库,但我需要使用进行汇总。一般来说,这是可行的。但是,如果从barrel index.js导入,如
import { IsInt } from 'class-validator';
它失败了,错误为
[!] Error: 'IsInt' is not exported by node_modules/class-validator/index.js
我可以配置Rollup,使其识别barrel导入吗?如果是这样,它是如何做到
import {isNotEmpty} from "class-validator";
export Service {
create(createdto)
{
const {name,age} = createdto;
@isNotEmpty()
name //using decorator to check whether name is null or
undefined
}
}
因为装饰器只对类方法有用,所以我不能在方法变量中使用它。它如何验证方法变量?
我试图使用ValidationPipe,但无论我如何编写代码,发送请求时都会收到以下警告:No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies。
我的路线是这样的:
@Get()
@UsePipes(new ValidationPipe({ transform: true }))
async findAll(@Query() queryDto: QueryDto) {
return await
我正在使用nest来制作Restfull Api。我还使用class-validator ,and class-transform来验证我对DTO的请求。目前,它正在显示此错误。
{"statusCode":400,"message":["username should not be empty","description should not be empty"],"error":"Bad Request"}
我想定制这样的回应
{"statusCode":400,"mes
假设我有一个基于文档中示例的类(https://github.com/typestack/class-validator#usage) import {MinLength, MaxLength, validate} from "class-validator";
export class Post {
@IsString()
body: strong;
@IsString()
title: string;
//...many more fields
public async validate(){
va
如何转换数据库实体User
class User {
public firstName: string;
public lastName: string;
public phone?: string;
public email: string;
public status: EUserState;
public tokens: Token[];
public password: string;
}
转换为DTO实体GetUserDTO
class GetUserDTO {
public id: number;
public firstName: string