Skip to content

Commit

Permalink
fix(schematype): handle passing message function to `SchemaType#val…
Browse files Browse the repository at this point in the history
…idate()` as positional arg

Fix #8360
  • Loading branch information
vkarpov15 committed Dec 4, 2019
1 parent 253e054 commit 491b9cc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/schematype.js
Expand Up @@ -676,21 +676,24 @@ SchemaType.prototype.get = function(fn) {
SchemaType.prototype.validate = function(obj, message, type) {
if (typeof obj === 'function' || obj && utils.getFunctionName(obj.constructor) === 'RegExp') {
let properties;
if (message instanceof Object && !type) {
if (typeof message === 'function') {
properties = { validator: obj, message: message };
properties.type = type || 'user defined';
} else if (message instanceof Object && !type) {
properties = utils.clone(message);
if (!properties.message) {
properties.message = properties.msg;
}
properties.validator = obj;
properties.type = properties.type || 'user defined';
} else {
if (!message) {
if (message == null) {
message = MongooseError.messages.general.default;
}
if (!type) {
type = 'user defined';
}
properties = {message: message, type: type, validator: obj};
properties = { message: message, type: type, validator: obj };
}

if (properties.isAsync) {
Expand Down

0 comments on commit 491b9cc

Please sign in to comment.