NestJS-方法处理程序正在干扰另一个控制器中具有相同名称的另一个处理程序 [英] NestJS - A method handler is interfering into another handler with same name in another controller

查看:166
本文介绍了NestJS-方法处理程序正在干扰另一个控制器中具有相同名称的另一个处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个控制器,两个不同的文件夹,两个不同的模块,两个都有一个具有相同create名称的方法.

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"}
    }
}

当我在两条路线中都张贴以下内容时:{"name": "test"}

When I do post the following in both routes: {"name": "test"},

admin create()方法记录的是body部分,而不是预期的requests.

It happens that admin create() method logs the body part, not the requests as expected.

user控制器的定义似乎正在干扰admin控制器,并使其无法正常工作.

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.

这是预期的行为吗?

推荐答案

您要覆盖EntityController,具体取决于Nest如何获取依赖项.更改其中一个类的名称. AdminController UserController之类的

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

这篇关于NestJS-方法处理程序正在干扰另一个控制器中具有相同名称的另一个处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆