조회 API를 만들기 위해 간단한 테스트 데이터를 넣고 로직을 짰었다. controller와 service랑 연관을 잘 지었다고 생각했지만..? 계속해서 404 에러가 발생했었다.
404 에러가 발생했던 이유에 대해서 생각했던 점은 다음과 같다.
1) Dev DB에 dummy(test) data가 없어서 -> 추가
그런데 Dev DB에 데이터를 추가했어도 계속해서 404 에러가 발생했던 것이었다.
{
"statusCode": 404,
"timestamp": "2023-08-18T03:08:25.690Z",
"path": "/v1/party-member/2",
"message": "Cannot GET /v1/party-member/2"
}
내가 작성했던 Controller.ts는 다음과 같다.
@Get()
@SwaggerBundle('전체 당원 조회', GetPartyMembersOutputDto, true)
async getPartyMembers(
@Param('id') id: number,
): Promise<GetPartyMembersOutputDto> {
return await this.partyMemberService.getPartyMembers(id);
}
문제는 여기서 발생했던 것이었다.
바로 메서드에서는 id를 파라미터로 받는데, @Get()을 조회할때 인자값이 빠져있던 것이다.
@Get('/:id')
@SwaggerBundle('전체 당원 조회', GetPartyMembersOutputDto, true)
async getPartyMembers(
@Param('id') id: number,
): Promise<GetPartyMembersOutputDto> {
return await this.partyMemberService.getPartyMembers(id);
}
id 파라미터값을 잘 넣어줬더니, postman에서 응답도 200코드로 잘 떨어졌다.
{
"timestamp": "2023-08-18T03:11:43.506Z",
"statusCode": 200,
"result": {}
}
'Backend > NestJS' 카테고리의 다른 글
Enum Type과 Enum 구조체 사용의 고민 (0) | 2023.08.24 |
---|---|
NestJS의 main.ts를 파헤쳐보자 (0) | 2023.08.23 |
Nestjs 프로젝트 생성하며 알게된점 (package.json 내부의 모듈역할, dependencies 그리고 devDependencies) (0) | 2023.08.18 |
zsh: command not found: nest 해결방법 (0) | 2023.08.17 |
Docker 빌드 에러 (0) | 2023.08.14 |