Shared custom unique class-validators with the database by using Nestjs and Prisma

Udhayakumar C
Oct 8, 2022

--

We can use the single validation function across the application to validate the unique field with database different entities. To do that, refer to the below steps

  1. Add the following lines to the main.ts file
useContainer(app.select(AppModule), { fallbackOnErrors: true });

2. Define the custom validators

3. Add the newly created custom validator in the app module’s providers array

4. Use the custom validator in the DTO wherever we want by passing the entity name

References

--

--

Udhayakumar C
Udhayakumar C

Written by Udhayakumar C

Senior Software Engineer @Yavar Tech Works

No responses yet