Nestjs Mongoose Tutorial #7 | DTO Validation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video uh we will learn how to implement validation so that uh our code catches the validation errors not uh the mongos so the very first step is for you to go to the main file and apply this validation pipe so import this here and then use app.use Global pipes and new validation pipe this will globally enable validation pipes in for your application so I have saved it here next step is for you to go to the D user then to the DTU and then to the create user DTU here you can see that uh nextjs by default only created an empty class so let's start working on it so first you have to you know import whatever uh validations you want to import currently I only need these validations for example I want to check uh is email or if it is not empty or if it is optional or if it is string and also the minimum length so this class validator uh is installed by fault in the repository that we started working on if you don't have it installed then make sure that you install it so this is uh the importing part you know pretty simple next step is you would do something like this so you define an email of type a string and then you put this as a decorator above so you want to make sure that whatever comes into the email property is a email you know that is why this decorator is used so you can use more than one decorators as well just like this so you can see that password is supposed to be a string um you know and you have put is a string is not empty and the minimum length of the password should be six just like that you can also make a certain property as an optional uh like I have put here for the first name as well as for the last name so create user D is uh ready so these are the very basic steps very first step is to make sure that you have have here enabled the global pipes for the validation okay and the next step is this so after these two steps are done uh what I would do is I would open the terminal uh and verify application is running so go to the Post pen and then this is my request where I was sending array of objects let's verify if it works now send here so it should be caught in our uh dto and it is saying to like like email must be an email and all the validations that we have put the reason being that the input is now expecting only an object not an array of object which is why it is generating this error so if I go over here and I put I send this so you can see the user is successfully generated so there are other things in you know validation bip as well for example um you can do uh you know transformation as well as uh wi listing and also of this stuff so I have put a separate video there for the entire explanation of dto I will add uh it in description below so this is all there is for the validation for our case so thank you for watching
Info
Channel: Shameel Uddin
Views: 43
Rating: undefined out of 5
Keywords: nestjs, nestjs mongodb, nestjs mongoose, mongodb, mongoose, nestjs mongoose tutorial, nestjs mongodb tutorial, nestjs tutorial, mongodb tutorial, mongoose tutorial, nestjs vs express, nestjs microservices, nest.js, nest.js mongodb, nestjs crash course, nestjs api, nestjs rest api, nestjs jwt, nestjs authentication, nestjs access token, nestjs jwt guard, nestjs passport, nestjs passport jwt, nestjs prisma, nestjs e2e, Shameel Uddin, nestjs/microservices, nestjs course
Id: pgLpsRrMJ8A
Channel Id: undefined
Length: 3min 17sec (197 seconds)
Published: Mon Mar 04 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.