NestJs Validation Tutorial 2021

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ต.ค. 2024
  • Request data validation is quite an important concept to write clean code.
    In this video, you will learn how to use Pipe and Data Transfer Object (DTO) validations in NestJs.
    Here is the Github repo with the code:
    github.com/vla...
    Follow me on Twitter to stay updated with the release of further tutorials
    / vladimir_agaev

ความคิดเห็น • 22

  • @CodeWithVlad
    @CodeWithVlad  3 ปีที่แล้ว

    I hope you loved this video! 🙂
    📮Consider subscribing to my newsletter: codewithvlad.substack.com
    🔥 And follow me on Twitter: twitter.com/vladimir_agaev

  • @IvoR87
    @IvoR87 2 ปีที่แล้ว +1

    Really good video! Especially the little nugget at the end of the video about removing the dist folder. When starting with NestJS I couldn't figure out why some dependency injections resulted in errors (missing modules/services and stuff). Felt like a "hallelujah" moment when I figured out the dist was caching code...

    • @CodeWithVlad
      @CodeWithVlad  2 ปีที่แล้ว

      Glad it helped!

    • @pashabiceps95
      @pashabiceps95 ปีที่แล้ว

      i hate this type of cash they just want you us to suffer

  • @flavienbesseau3210
    @flavienbesseau3210 2 ปีที่แล้ว

    Thanks for the video. That was not clear for me and you really well explained ! You also have a nice accent to understand =)

  • @mohandamokraneabdiche1051
    @mohandamokraneabdiche1051 2 ปีที่แล้ว

    Great tutorial Vlad, keep up the good work, you are a very good explainer

  • @SRMatan
    @SRMatan 2 ปีที่แล้ว +1

    Great tutorial! Thanks!

  • @lpa9189
    @lpa9189 2 ปีที่แล้ว

    Hey nice video! Can you please tell me the software you used in order to write with you Wacom directly on the Desktop?

  • @arupde6320
    @arupde6320 3 ปีที่แล้ว +1

    keep uploading ..

  • @Cognitoman
    @Cognitoman ปีที่แล้ว +1

    Why does nest do validation inside the controller is that validations are business rules for the entity or model?

    • @pashabiceps95
      @pashabiceps95 ปีที่แล้ว

      same question, it is too stupid, typeorm or sequelize checks the data, so DB is not the case when you want to do this type of validation

  • @Mumbairandomvlogs
    @Mumbairandomvlogs 3 ปีที่แล้ว

    Nice tutorial, Thanks Vlad.

  • @user-tt6nc6mo7k
    @user-tt6nc6mo7k 2 ปีที่แล้ว

    Hey Vlad, how would you re-use your dtos and class-validator on the frontend?

    • @CodeWithVlad
      @CodeWithVlad  2 ปีที่แล้ว

      Generally, you would avoid as it's messy. If you really want to re-use you would create an npm package with those dtos and import those in frontend and backend. But then it's better to use GraphQL because it solves this problem

    • @user-tt6nc6mo7k
      @user-tt6nc6mo7k 2 ปีที่แล้ว +1

      @@CodeWithVlad I see, I feel like its messy not re-using the dtos. I work on a couple projects some with a different language on the backend (Laravel). And it feels weird having to keep 2 different sets of almost identical validaiton checks in sync.
      I was hoping for my projects with Typescript on the frontend and the backend I would just re-use the dtos. And that seems to be what you are suggesting. I think I am going to go with the monorepo approach though instead of an npm package.
      Since you mentioned graphql, it would be amazing if you could do the same sort of thing that you did on freecodecamp recently but with graphql. P.s that course on freecodecamp is the best nodejs course ever! Very well put together, concise and to the point with all the details you need to get started. And I really like your TDD approach with pactum.js, I personally like combining pactum with cucmber.js when testing my APIs.

    • @CodeWithVlad
      @CodeWithVlad  2 ปีที่แล้ว +1

      ​@@user-tt6nc6mo7k Well that's one of the main issues GraphQl is fixing :) Monorepos can work! Although i'm not a fan of mixing projects, has led to some weird behaviours (probably due to the fact that i did not understand how to work with them properly).
      Only issue is that if you want to share the dtos with something like react I usually use types and interfaces there, not classes. The class dtos I use on the backend not only provides typings but also validate the request. So a bit hard to re-use (especially when using mapped types docs.nestjs.com/techniques/validation#mapped-types)
      Anyway, I will repeat myself again. GraphQL solves that :)
      And my graphql course is work in progress. Sadly I'm a bit busy with work atm but it is wip!

  • @jmp2688
    @jmp2688 2 ปีที่แล้ว

    Great Video!! THX

    • @CodeWithVlad
      @CodeWithVlad  2 ปีที่แล้ว

      I’m happy you loved it!

  • @mostaphaamghare313
    @mostaphaamghare313 3 ปีที่แล้ว

    global validationPipe run before DTO so how validationPipe validate DTO

  • @nazarromanchuk6080
    @nazarromanchuk6080 3 ปีที่แล้ว

    Great tutorial! Thanks!