Skip to content

Conversation

vinczedani
Copy link
Contributor

@vinczedani vinczedani commented Sep 6, 2018

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

@wheresvic
Copy link
Owner

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!

Copy link
Owner

@wheresvic wheresvic left a 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.

let plainTextValue = this._update.$set[field] || this._update[field];

if (encryptedFieldValue === false && plainTextValue) {
if (plainTextValue) {
Copy link
Owner

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.

Copy link
Owner

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 :)

Copy link
Contributor Author

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

return next(
new Error("Cannot apply mongoose-field-encryption plugin on update to encrypt non string fields")
);
const encryptedFileData = encryptedFieldName + encryptedFieldDataSuffix;
Copy link
Owner

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

@vinczedani
Copy link
Contributor Author

I think I fixed the changes you requested.
I agree that this change is just a minor update, since it doesn't break the current interface.

@wheresvic wheresvic merged commit bf5b4bf into wheresvic:master Sep 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants