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 :: add elements to middle of array using splice 
Typescript :: how to extract digits of a number in c 
Typescript :: remove all children of node in typescript 
Typescript :: laravel update if exists or create 
Typescript :: value of input in typescript 
Typescript :: foreach on dictionary in typescript 
Typescript :: create jwt token typescript 
Typescript :: ionic copy to clipboard 
Typescript :: already exists http status code 
Typescript :: union of two sets python syntax 
Typescript :: http requests in spring boot 
Typescript :: no provider for childrenoutletcontexts angular 
Typescript :: what is test management review 
Typescript :: go build could not read username 
Typescript :: Give each of the radio and checkbox inputs the value attribute. Use the input label text, in lowercase, as the value for the attribute. 
Typescript :: React Typescript form event 
Typescript :: mat dialog block scroll 
Typescript :: ggplots in r 
Typescript :: How to do Email validation using Regular expression in Typescript 
Typescript :: merge enum typescript 
Typescript :: set element disable in typescript 
Typescript :: docx to pdf javascript 
Typescript :: where are screenshots stored steam 
Typescript :: node fetch image to base64 
Typescript :: check runnong ports ubuntu 
Typescript :: sort an arraylist of objects in java 
Typescript :: typescript debounce 
Typescript :: typescript array of mixed types 
Typescript :: nestjs get request header in guard 
Typescript :: check if graphic driver exists ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =