In my NestJS controller, I have defined a route for updating locality information. The structure of the controller method is as follows:
@Put('/:id')
updateLocalityInfo(
@Query('type') type: string,
@Body() data: EditLocalityDto,
@Body('parentId', ParseIntPipe) parentId: number,
@Param('id', ParseIntPipe) id: number,
) {
console.log(data);
return this.localitiesService.updateLocalityInformation(
type,
data,
id,
parentId,
);
}
While working with this route, I encountered an issue related to the Dto and the parentId variable. It appears that when I call the route, the parentId
value is included in the Dto-data. Upon logging the data, I observed the following output:
{ name: 'exampleName', parentId: '1' }
The EditLocalityDto class, however, only contains a property for the name:
import { ApiProperty } from '@nestjs/swagger';
export class EditLocalityDto {
@ApiProperty()
name: string;
}
I am seeking a solution to remove the parentId from being part of the dto-data. How can I achieve this adjustment in a general context?