xiaohantx
V2EX  ›  Node.js

学习 Nestjs 请教一下

  •  
  •   xiaohantx · Aug 19, 2024 · 2313 views
    This topic created in 649 days ago, the information mentioned may be changed or developed.

    core/controller/user/user.controller.ts 文件里引用了自定义的管道 ValidationPipe

    但是为什么 core/pipe/validation-pipe.ts 这个管道不生效呀

    if (!metatype || !this.toValidate(metatype)) { return value; }

    这里两个值都是 false ,后面就不运行了,没有进行类型校验

    5 replies    2024-08-20 15:52:36 +08:00
    taotaoHH
        2
    taotaoHH  
       Aug 19, 2024
    不用全局验证吗 app.useGlobalPipes(new ValidationPipe());
    xiaohantx
        3
    xiaohantx  
    OP
       Aug 19, 2024 via iPhone
    @taotaoHH 应该就这个控制器绑定也可以吧,我看已经运行到管道了就是走不下去跟预期不一样
    zieglar
        4
    zieglar  
       Aug 20, 2024
    ```@Body(new ValidationPipe()) body: any```
    xiaohantx
        5
    xiaohantx  
    OP
       Aug 20, 2024
    @zieglar 已经解决了 t/1066320
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   901 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 20:04 · PVG 04:04 · LAX 13:04 · JFK 16:04
    ♥ Do have faith in what you're doing.