-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from sirkenedy/class-validator
[IMP] class validator
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
import { Users as User } from '../../users/entities/user.entity'; | ||
import { IsNotEmpty, IsString, isArray } from 'class-validator'; | ||
|
||
export class CreateBookDto { | ||
@IsNotEmpty({"message" : "Book title cannot be empty"}) | ||
@IsString({"message" : "Book title must be of type string"}) | ||
title: string; | ||
|
||
@IsNotEmpty({"message" : "Book description cannot be empty"}) | ||
@IsString({"message" : "Book desciption must be of type string"}) | ||
description: number; | ||
|
||
@IsNotEmpty({"message" : "Book thumnail cannot be empty"}) | ||
@IsString({"message" : "Book thumbnail must be of type string"}) //@isUrl can be used to verify that it is a valid url | ||
thumbnail: string; | ||
|
||
@IsNotEmpty({"message" : "Book author cannot be empty"}) | ||
author: string[]; | ||
|
||
@IsNotEmpty({"message" : "Seems like something went wrong! please try again"}) | ||
user : User | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
import { IsNotEmpty, IsEmail } from 'class-validator'; | ||
|
||
export class CreateUserDto { | ||
@IsNotEmpty({"message" : "Name field cannot be empty"}) | ||
name: string; | ||
|
||
@IsEmail({"message" : "Enter a valid email adress"}) | ||
email: number; | ||
|
||
@IsNotEmpty({"message" : "Password field cannot be empty"}) | ||
password: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
import { ValidationPipe } from '@nestjs/common'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
app.useGlobalPipes(new ValidationPipe({ | ||
whitelist: true, | ||
transform: true, | ||
})); | ||
await app.listen(3000); | ||
} | ||
bootstrap(); |