Skip to content
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

Merged
merged 5 commits into from
Sep 7, 2018

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.


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

test/test-db.js Show resolved Hide resolved
test/test-db.js Show resolved Hide resolved
@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