-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add findOneAndUpdate and without $set support #20
Conversation
Hi @vinczedani Thanks a lot for taking the time to contribute and raise a PR :) I had a look at it and I have some suggestions before I can merge this in! I hope you can do them but if not, let me know and I can also do some of them, Cheers! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, I would like to have your opinion if this should be a major change or not.
I am personally tending to keeping this as a minor change as it is just a feature addition.
lib/mongoose-field-encryption.js
Outdated
|
||
if (encryptedFieldValue === false && plainTextValue) { | ||
if (plainTextValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the check for encryptedFieldValue === false
is removed now. This is very necessary as the value might be double encrypted if it is passed to the update statement by mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably also add a test for this case :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right :) I'll try to cover it with a test somehow
lib/mongoose-field-encryption.js
Outdated
return next( | ||
new Error("Cannot apply mongoose-field-encryption plugin on update to encrypt non string fields") | ||
); | ||
const encryptedFileData = encryptedFieldName + encryptedFieldDataSuffix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename variable to encryptedFieldData
I think I fixed the changes you requested. |
This pr should add the missing hook for findOneAndUpdate since it is a native mongodb call, mongoose has different calls for that and update.
It should also add a feature to work with $set and without $set.
Closes #14