This file contains hidden or 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
| import { Module } from '@nestjs/common'; | |
| import { APP_PIPE } from '@nestjs/core'; | |
| @Module({ | |
| providers: [ | |
| { | |
| provide: APP_PIPE, | |
| useClass: CustomeValidationPipe, | |
| }, | |
| ], |
This file contains hidden or 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
| async function bootstrap() { | |
| const app = await NestFactory.create(AppModule); | |
| app.useGlobalPipes(new CustomeValidationPipe ()); | |
| await app.listen(3000); | |
| } | |
| bootstrap(); |
This file contains hidden or 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
| import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common'; | |
| @Injectable() | |
| export class CustomeValidationPipe implements PipeTransform { | |
| transform(value: any, metadata: ArgumentMetadata) { | |
| return value; | |
| } | |
| } |
This file contains hidden or 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
| @Get(':id') | |
| @UsePipes(ParseUUIDPipe) | |
| getBookById(@Param('id') id: string){ | |
| return this.bookService.findBookById(); | |
| } |
This file contains hidden or 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
| @Get(':id') | |
| getBookById(@Param('id', ParseUUIDPipe) id: string){ | |
| return this.bookService.findBookById(); | |
| } |
This file contains hidden or 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
| Method Name | Description | |
|---|---|---|
| concat() | Joins arrays and returns an array with the joined arrays | |
| copyWithin() | Copies array elements within the array, to and from specified positions | |
| every() | Checks if every element in an array passes a test | |
| fill() | Fill the elements in an array with a static value | |
| filter() | Creates a new array with every element in an array that passes a test | |
| find() | Returns the value of the first element in an array that passed a test | |
| findIndex() | Returns the index of the first element in an array that passed a test | |
| flat() | creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. | |
| flatMap() | returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level. |
This file contains hidden or 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
| import { Module } from "@nestjs/common"; | |
| import { FuelStationController } from "src/controllers"; | |
| import { APP_FILTER } from '@nestjs/core'; | |
| import { HttpExceptionFilter } from "src/exceptions"; | |
| @Module({ | |
| controllers: [FuelStationController], | |
| providers: [ | |
| { |
This file contains hidden or 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
| async function bootstrap() { | |
| const app = await NestFactory.create(FuelStationModule); | |
| app.useGlobalFilters(new HttpExceptionFilter()); | |
| await app.listen(3000); | |
| } | |
| bootstrap(); |
This file contains hidden or 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
| @Controller('stations') | |
| @UseFilters(new HttpExceptionFilter()) | |
| export class FuelStationController { | |
| } |
This file contains hidden or 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
| @Get() | |
| @UseFilters(HttpExceptionFilter) | |
| getFuelForTokenHolders(){ | |
| throw new CustomFuelStationException('Fuel token is not valid', HttpStatus.UNAUTHORIZED) | |
| } |
NewerOlder