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! |
wheresvic
left a comment
There was a problem hiding this comment.
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
| let plainTextValue = this._update.$set[field] || this._update[field]; | ||
|
|
||
| if (encryptedFieldValue === false && plainTextValue) { | ||
| if (plainTextValue) { |
There was a problem hiding this comment.
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.
We should probably also add a test for this case :)
There was a problem hiding this comment.
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.
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