728x90
컨트롤러
int타입의 id 사용하기
import { Controller, Get, Param, BadRequestException } from '@nestjs/common';
@Get('/:achievementCId')
findOne(@Param('achievementCId') achievementCId: string) {
const id = Number(achievementCId);
if (!id) {
throw new BadRequestException('achievementCId 값이 없거나 형태가 맞지 않습니다');
}
return this.achievementCService.findOne(+id);
}
쿼리 사용하기
import { Controller, Get, Param, Query } from '@nestjs/common';
@Get()
findByCategory(@Query('category') category?: string) {
if (category) {
return this.achievementService.findCategory(category);
}
return this.achievementService.findAll();
}
'내일배움 정리 > JS 문법 공부' 카테고리의 다른 글
nestJs CURD 레포지토리 (0) | 2025.02.18 |
---|---|
NestJs - HTTP 예외 처리 클래스 (0) | 2025.02.14 |
NestJs란 (0) | 2025.02.13 |
NestJS에서 TypeORM을 사용할 때 Repository에서 제공하는 주요 메서드 (0) | 2025.02.13 |
NestJS - IsDate() vs @IsDateString() (0) | 2025.02.13 |