-
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.
AB#151 feat: add global NestJS validation pipe
- Loading branch information
1 parent
bda255d
commit 1d22efa
Showing
10 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
Binary file added
BIN
+57.9 KB
service/.yarn/cache/@types-validator-npm-13.11.9-ac3f0e748e-2d397c6929.zip
Binary file not shown.
Binary file added
BIN
+240 KB
service/.yarn/cache/class-transformer-npm-0.5.1-96b5161e6c-750327e3e9.zip
Binary file not shown.
Binary file added
BIN
+1.42 MB
service/.yarn/cache/class-validator-npm-0.14.1-f0ce3b1130-0c34592a1c.zip
Binary file not shown.
Binary file added
BIN
+2.2 MB
service/.yarn/cache/libphonenumber-js-npm-1.10.57-b94f521f3d-7344dd7e8f.zip
Binary file not shown.
Binary file not shown.
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,11 @@ | ||
import {NestFactory} from "@nestjs/core" | ||
import {AppModule} from "./app.module" | ||
import {globalValidationPipe} from "./validation-pipe" | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule) | ||
app.useGlobalPipes(globalValidationPipe) | ||
await app.listen(3000) | ||
} | ||
|
||
bootstrap() |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {BadRequestException, ValidationPipe} from "@nestjs/common" | ||
|
||
export const globalValidationPipe = new ValidationPipe({ | ||
stopAtFirstError: false, | ||
exceptionFactory: errors => { | ||
const mappedErrors = [] | ||
|
||
for (const error of errors) { | ||
for (const key in error.constraints) { | ||
mappedErrors.push({ | ||
code: "VALIDATION_ERROR", | ||
message: error.constraints[key] | ||
}) | ||
} | ||
} | ||
|
||
return new BadRequestException({ | ||
errors: mappedErrors | ||
}) | ||
} | ||
}) |
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
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