관리 메뉴

Silver Library (Archived)

nestjs - when to and not to use dto? 본문

카테고리 없음

nestjs - when to and not to use dto?

Chesed Kim 2023. 3. 19. 16:41
반응형

Case 1. When there are two, but only one parameter.

@Patch('/:id/status')
updateTaskStatus(
	@Param('id') id: string,
    @Body('status') status: TaskStatus,
): Task {
	return this.tasksService.updateTaskStatus(id, status);
}

Note: parameter(@Param) and @body, both has a single parameter('id', 'status') and property(id, status).

 

In this code snippet, id is a parameter and status is a property.

 

@Param('id') is a decorator that extracts the value of id from the request URL parameters and binds it to the method parameter id.

 

@Body('status') is a decorator that extracts the value of status from the request body and binds it to the method parameter status. 

 

Therefore, id is a parameter because it is being passed into the function as an argument, while status is a property because it is being assigned a value from the request body.