QueryString용 DTO 제작 방식

Query String은 기본적으로 String으로 들어오기에, Transform을 진행해준다.

→ @Transform Decorator를 사용하여 Number로 Value값을 변화시켜준다.

@ApiPropertyOptional을 적용해서 Required : false를 해주고, default는 1로 해주는 모습

import { ApiPropertyOptional } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsInt } from 'class-validator';

export class PageReqDto {
  // 페이지 관련 Dto
  @ApiPropertyOptional({ description: '페이지. default = 1' })
  @Transform((param) => Number(param.value))
  @IsInt()
  page?: number = 1;

  @ApiPropertyOptional({ description: '페이지당 데이터 갯수. default = 20' })
  @Transform((param) => Number(param.value))
  @IsInt()
  size?: number = 20;
}

참조