mongoose-sort-encrypted-field
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -39,12 +39,3 @@ "use strict"; | ||
schema["options"].sortEncryptedFieldsOptions = sortEncryptedFieldsOptions; | ||
schema.post("save", async function save(doc, next) { | ||
for (const [fieldName, sortFieldName] of Object.entries(sortFields)) { | ||
await modelsQueue.addJob(`${this.constructor["modelName"]}::${fieldName}::${sortFieldName}`, { | ||
objectId: doc._id, | ||
fieldValue: doc[fieldName], | ||
}); | ||
} | ||
next(); | ||
}); | ||
schema.pre("updateOne", async function preUpdateOne(next) { | ||
async function preUpdateOne(next) { | ||
const update = this.getUpdate(); | ||
@@ -62,4 +53,4 @@ for (const fieldName in sortFields) { | ||
next(); | ||
}); | ||
schema.post("updateOne", async function postUpdateOne(res, next) { | ||
} | ||
async function postUpdateOne(res, next) { | ||
const update = this.getUpdate(); | ||
@@ -84,18 +75,13 @@ for (const fieldName in sortFields) { | ||
next(); | ||
}); | ||
schema.pre("updateMany", async function preUpdateMany(next) { | ||
const update = this.getUpdate(); | ||
for (const fieldName in sortFields) { | ||
const sortFieldName = sortFields[fieldName]; | ||
if (update["$set"] && update["$set"][sortFieldName]) { | ||
// Bypass middleware internal call for updating any sortFieldName field | ||
break; | ||
} | ||
if (update["$set"] && update["$set"][fieldName]) { | ||
update["$set"][sortFieldName] = null; | ||
} | ||
} | ||
async function postSave(doc, next) { | ||
for (const [fieldName, sortFieldName] of Object.entries(sortFields)) { | ||
await modelsQueue.addJob(`${this.constructor["modelName"]}::${fieldName}::${sortFieldName}`, { | ||
objectId: doc._id, | ||
fieldValue: doc[fieldName], | ||
}); | ||
} | ||
next(); | ||
}); | ||
schema.post("updateMany", async function postUpdateMany(res, next) { | ||
} | ||
async function postUpdateMany(res, next) { | ||
const update = this.getUpdate(); | ||
@@ -122,3 +108,10 @@ for (const fieldName in sortFields) { | ||
next(); | ||
}); | ||
} | ||
schema.pre("updateOne", preUpdateOne); | ||
schema.post("updateOne", postUpdateOne); | ||
schema.pre("findOneAndUpdate", preUpdateOne); | ||
schema.post("findOneAndUpdate", postUpdateOne); | ||
schema.pre("updateMany", preUpdateOne); | ||
schema.post("save", postSave); | ||
schema.post("updateMany", postUpdateMany); | ||
} | ||
@@ -125,0 +118,0 @@ function getModelWithSortEncryptedFieldsPlugin(documentName, schema, pluginOptions) { |
{ | ||
"name": "mongoose-sort-encrypted-field", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Mongoose plugin to enable sorting on encrypted fields", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60659
1762