Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

add all dto fields into query object if doesn't into query NestJs

I’ve been working in NestJs. I try to add in the object of @Query(), all the fields that were not entered in the query:

Dto:

{
    a: number = null
    b: number = null
    c: number = null
}

Ex request:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

POST url?a=5

I get:

query = {a:5}

I need:

query = {a: 5, b: null, c: null}

>Solution :

You need to enable the transformation on ValidationPipe like so: new ValidationPipe({ transform: true })

The default is false for performance reasons (I guess), which makes that query not an instance of your DTO

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading