NestJS - A method handler is interfering into another handler with same name in another controller

感情迁移 提交于 2019-12-13 04:19:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!