nestjs-class-validator-db
Installation
npm install nestjs-class-validator-db
or
yarn add nestjs-class-validator-db
Usage :
// main.ts
import { useContainer } from 'class-validator'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
app.useGlobalPipes(new ValidationPipe())
useContainer(app.select(AppModule), { fallbackOnErrors: true })
...
}
bootstrap()
// app.module.ts
import { DbClassValidatorModule } from 'nestjs-class-validator-db'
@Module({
imports: [
...
DbClassValidatorModule
],
...
})
export class AppModule {}
// x.dto.ts
import { IsUnique } from 'nestjs-class-validator-db'
import { User } from '../entities/user.entity'
export class UserDto {
@IsUnique(User)
@IsEmail()
email: string
}