marchah / mongoose-draft

Mongoose draft plugin to disable the model validation
MIT License
1 stars 1 forks source link

Documentation on pre-validate code chunk? #1

Open hems opened 1 year ago

hems commented 1 year ago

Hello,

Thanks a lot for sharing the code. I have searched for "mongoose draft" and the only thing i found is your 7 years old project!

I wonder what does exactly this chunk of code does and why it exists? Seems like you had to deal with some code i can't find documentation for..

https://github.com/marchah/mongoose-draft/blob/a35e15b199eae3016b6649098751a4bab0beb13f/lib/draft.js#L49-L60

For instance $__.activePaths.states.modify

marchah commented 1 year ago

Sorry for the late reply.

Not 100% it was so long ago but i think it's because the validations only run on modified fields, so once you set the doc as non draft i marked all the fields as modified, set the validation function back like then mongoose will validate all the fields.

Let me know if it's not clear.