mongoose-unique-validator
Advanced tools
Comparing version 0.5.0 to 0.5.1
36
index.js
@@ -13,3 +13,3 @@ 'use strict'; | ||
if (indexOptions.unique) { | ||
paths.forEach(function(path) { | ||
paths.forEach(function(pathName) { | ||
var pathMessage = message; | ||
@@ -20,19 +20,23 @@ if (typeof indexOptions.unique === 'string') { | ||
schema.path(path).validate(function(value, respond) { | ||
var doc = this; | ||
var path = schema.path(pathName); | ||
var conditions = []; | ||
paths.forEach(function(path) { | ||
var condition = {}; | ||
condition[path] = doc[path]; | ||
conditions.push(condition); | ||
}); | ||
if (path) { | ||
path.validate(function(value, respond) { | ||
var doc = this; | ||
// Awaiting more official way to obtain reference to model. | ||
// https://github.com/Automattic/mongoose/issues/3430 | ||
var model = doc.model(doc.constructor.modelName); | ||
model.where({ $and: conditions }).count(function(err, count) { | ||
respond(((doc.isNew && count === 0) || (!doc.isNew && count === 1))); | ||
}); | ||
}, pathMessage); | ||
var conditions = []; | ||
paths.forEach(function(name) { | ||
var condition = {}; | ||
condition[name] = doc[name]; | ||
conditions.push(condition); | ||
}); | ||
// Awaiting more official way to obtain reference to model. | ||
// https://github.com/Automattic/mongoose/issues/3430 | ||
var model = doc.model(doc.constructor.modelName); | ||
model.where({ $and: conditions }).count(function(err, count) { | ||
respond(((doc.isNew && count === 0) || (!doc.isNew && count <= 1))); | ||
}); | ||
}, pathMessage); | ||
} | ||
}); | ||
@@ -39,0 +43,0 @@ } |
{ | ||
"name": "mongoose-unique-validator", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "mongoose-unique-validator is a plugin which adds pre-save validation for unique fields within a Mongoose schema.", | ||
@@ -5,0 +5,0 @@ "main": "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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
21325
341
0