问题
I had two controllers into two differnt folders into two different modules, Both of them has a method with same create name.
/admin/entity.controller.ts
@Controller("admin")
export class EntityController{
@Post()
public async create(@Request() request: any): Promise<List> {
console.log("request", request) // Logs the Body {"name": "test"} instead of request.
}
}
/user/entity.ontroller.ts
@Controller("user")
export class EntityController{
@Post()
public async create(@Body() entity: Entity) {
console.log("entity", entity) // logs the body {"name": "test"}
}
}
When I do post the following in both routes: {"name": "test"},
It happens that admin create() method logs the body part, not the requests as expected.
It seems to be that the definition of the user controller is interfering into the admin controller and making it to do not work properly.
Is this an expected behaviour?
回答1:
You're overriding the EntityController depending on how Nest pulls in the dependencies. Change the name of one of the classes. AdminController UserController or something
来源:https://stackoverflow.com/questions/57244179/nestjs-a-method-handler-is-interfering-into-another-handler-with-same-name-in