Form/Data Body returns [Object: null prototype] { id: 'df4f8rfrf' } in nestjs / nodejs

Viewed 623

I follow this link but it's not working for me. When I am trying to pass form data to my database, My controller returns

categories: [Object: null prototype] { id: '3a0e56cc-5670-4dcc-9bbd-8ef38d2b1535' }

But I don't know the reason. The data should return like this: enter image description here

This is my code :

 @Post()
  @UseInterceptors(FileInterceptor('image'))
  async create(
    @UploadedFile() file: Express.Multer.File,
    @Body() createItemDto: CreateItemDto,
  ) {
    console.log('createItemDto', createItemDto);
    try {
      const item = await this.itemService.create(createItemDto);
      if (item) {
          return {
            statusCode: HttpStatus.OK,
            message: 'Item created successfully',
            item,
             };
      }

    } catch (error) {
      return {
        message: error.detail,
      };
    }
  }

This is what my error looks like : I really need your all help. Because I have no idea about this. enter image description here

1 Answers

There is probably a better way to do this but I did something like this:

const obj = JSON.parse(JSON.stringify(abc)); // abc = [Object: null prototype] { id: '123' }

console.log(obj); // { id: '123' }
Related