How nestjs validates some parameters.

according to nest.js official documents, request parameter verification is implemented using class-validator and pipe , but
can only be fully verified according to the rules defined when the entity is defined, that is, the verification rules in the entity must be fully satisfied each time.
in fact, more requirements are that all rules must be checked when added, and only validated against the request parameters when modified (for example, if only one field is modified and the request parameter is this field, only that field will be verified. ), and no check is required for deletion

refer to some articles and materials and find some useful information: class-validator comes with Skipping missing properties , and Entity Listeners and Subscribers of typeorm .

but the level is limited, and I don"t know how to achieve it, so I turn to the community gods.

Boss ask for help!

Feb.28,2021

saw the invitation and came in.
does not understand nest.js , and the information about the attempt is not included in the question. Check the relevant content for you to see if it is helpful to you.

has the same problem resolution as the landlord
nest issue
typestack (class-validator team) subitem issue


I finally used class-validate 's isOptional


the best way is to first define a baseDto, that contains all the fields and add verification rules. Then both the addDTo for the new interface and the updateDto for the modified interface inherit baseDto, and rewrite the verification rules for some fields according to their own needs.

Menu