Skip to content

Commit

Permalink
refactor: use SchemaNumberOptions class for schematype number re: #8012
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 6, 2019
1 parent 166cd88 commit 2d0955d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
44 changes: 44 additions & 0 deletions lib/options/SchemaNumberOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

const SchemaTypeOptions = require('./SchemaTypeOptions');

class SchemaNumberOptions extends SchemaTypeOptions {}

const opts = {
enumerable: true,
configurable: true,
writable: true,
value: null
};

/**
* If set, Mongoose adds a validator that checks that this path is at least the
* given `min`.
*
* @api public
* @property min
* @memberOf SchemaNumberOptions
* @type Number
* @instance
*/

Object.defineProperty(SchemaNumberOptions.prototype, 'min', opts);

/**
* If set, Mongoose adds a validator that checks that this path is at least the
* given `max`.
*
* @api public
* @property max
* @memberOf SchemaNumberOptions
* @type Number
* @instance
*/

Object.defineProperty(SchemaNumberOptions.prototype, 'max', opts);

/*!
* ignore
*/

module.exports = SchemaNumberOptions;
2 changes: 2 additions & 0 deletions lib/schema/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

const MongooseError = require('../error/index');
const SchemaNumberOptions = require('../options/SchemaNumberOptions');
const SchemaType = require('../schematype');
const castNumber = require('../cast/number');
const handleBitwiseOperator = require('./operators/bitwise');
Expand Down Expand Up @@ -106,6 +107,7 @@ SchemaNumber.schemaName = 'Number';
*/
SchemaNumber.prototype = Object.create(SchemaType.prototype);
SchemaNumber.prototype.constructor = SchemaNumber;
SchemaNumber.prototype.OptionsConstructor = SchemaNumberOptions;

/*!
* ignore
Expand Down
2 changes: 1 addition & 1 deletion lib/schema/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ SchemaString.schemaName = 'String';
*/
SchemaString.prototype = Object.create(SchemaType.prototype);
SchemaString.prototype.constructor = SchemaString;
SchemaString.prototype.OptionsConstructor = SchemaStringOptions;

/*!
* ignore
*/

SchemaString._cast = castString;
SchemaString.OptionsConstructor = SchemaStringOptions;

/**
* Get/set the function used to cast arbitrary values to strings.
Expand Down
6 changes: 6 additions & 0 deletions lib/schematype.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ function SchemaType(path, options, instance) {
});
}

/*!
* ignore
*/

SchemaType.prototype.OptionsConstructor = SchemaTypeOptions;

/**
* Get/set the function used to cast arbitrary values to this type.
*
Expand Down

0 comments on commit 2d0955d

Please sign in to comment.