Open datngoNFQ opened 2 years ago
For more information, after installed and use CRUD of nestjsx libraries, event a simple controller as below would receive empty object from HTTP POST from Postman
import { Body, Controller, Get, Post } from '@nestjs/common';
import { AppService } from './app.service';
import { ObjectDto } from './dto/Object.dto';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Post('subscribe')
subscribe(@Body() objectDto: ObjectDto) {
console.log(objectDto);
return '';
}
}
below is my DTO:
import { IsNotEmpty, IsDefined } from 'class-validator';
export class TenantDto {
@IsDefined()
@IsNotEmpty()
tenantName: string;
@IsDefined()
@IsNotEmpty()
tenantId: string;
}
import { IsNotEmpty, IsDefined } from 'class-validator';
export class ObjectDto {
@IsDefined()
@IsNotEmpty()
objectName: string;
@IsDefined()
@IsNotEmpty()
objectId: string;
}
Update: When I use HTTP POST with Content-Type as application/json, then it works.
I expect to have a simple config key at Controller to switch into FormData.
I'm able to use Postman to save data to DB by JSON. But when using FormData, at Controller, I have Empty object for CrudRequest, and the Entity Object
Follow another issue at: https://github.com/nestjsx/crud/issues/541 . Then, within my controller, I implemented code as below:
Both req, and dto are empty.
Below are the dependencies that I use for my nestjs project