Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

nest js parseint pipe usage

import { PipeTransform, Injectable, ArgumentMetadata, BadRequestException } from '@nestjs/common';

@Injectable()
export class ParseIntPipe implements PipeTransform<string, number> {
  transform(value: string, metadata: ArgumentMetadata): number {
    const val = parseInt(value, 10);
    if (isNaN(val)) {
      throw new BadRequestException('Validation failed');
    }
    return val;
  }
}

// usage

@Get(':id')
async findOne(@Param('id', new ParseIntPipe()) id) {
  return this.catsService.findOne(id);
}

@Get(':id')
findOne(@Param('id', UserByIdPipe) userEntity: UserEntity) {
  return userEntity;
}
Comment

nest js parseint pipe

import { PipeTransform, Injectable, ArgumentMetadata, BadRequestException } from '@nestjs/common';

@Injectable()
export class ParseIntPipe implements PipeTransform<string, number> {
  transform(value: string, metadata: ArgumentMetadata): number {
    const val = parseInt(value, 10);
    if (isNaN(val)) {
      throw new BadRequestException('Validation failed');
    }
    return val;
  }
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript http request 
Typescript :: ts Decorator pattern 
Typescript :: typescript object destructuring 
Typescript :: nestjs mongoose schema 
Typescript :: basic variable types typescript 
Typescript :: write a script that prints hello world followed by a new line to the standard output in linux 
Typescript :: interact with blockchain from nextjs 
Typescript :: call function dynamically typescript 
Typescript :: typescript pass a function as an argunetn 
Typescript :: Type annotations can only be used in TypeScript files.ts(8010) 
Typescript :: components of cucumber bdd framework 
Typescript :: typescript http get attach headers 
Typescript :: typescript function return type observable 
Typescript :: createasyncthunk with typescript 
Typescript :: sails.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies 
Typescript :: react tailwind css components npm 
Typescript :: typeorm decrement 
Typescript :: two absolute elements are overlapping css help 
Typescript :: ract import image 
Typescript :: angular sort string 
Typescript :: rewrite requests htaccess 
Typescript :: why important testng xml file 
Typescript :: symbol typescript 
Typescript :: namespaces typescript 
Typescript :: How to use the Generic Type Format for Arrays in Typescript 
Typescript :: paper menu rendered but not clickable 
Typescript :: how to compra vales on lists python 
Typescript :: undetermined number of arguments in function r 
Typescript :: how to git pull all projects in a folder 
Typescript :: how to implement loudspeaker in web development 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =