UNPKG

@joktec/mongo

Version:

JokTec - Mongo Service

40 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NumberProps = NumberProps; const utils_1 = require("@joktec/utils"); const lodash_1 = require("lodash"); function NumberProps(opts, swagger) { const decorators = []; decorators.push((0, utils_1.IsNumber)({}, { each: swagger.isArray })); if (opts.unsigned) { opts.min = [0, undefined]; if ((0, lodash_1.isArray)(opts.unsigned) && opts.unsigned[1]) { opts.min = [0, opts.unsigned[1]]; } } if (!(0, lodash_1.isNil)(opts.min)) { const defMsg = '$property must be greater than equals $constraint1'; if ((0, lodash_1.isArray)(opts.min) && (0, lodash_1.isNumber)(opts.min[0])) { decorators.push((0, utils_1.Min)(opts.min[0], { message: opts.min[1] || defMsg, each: swagger.isArray })); swagger.minimum = opts.min[0]; } if ((0, lodash_1.isNumber)(opts.min)) { decorators.push((0, utils_1.Min)(opts.min, { message: defMsg, each: swagger.isArray })); swagger.minimum = opts.min; } } if (!(0, lodash_1.isNil)(opts.max)) { const defMsg = '$property must be lower than equals $constraint1'; if ((0, lodash_1.isArray)(opts.max) && (0, lodash_1.isNumber)(opts.max[0])) { const validatorOption = { message: opts.max[1] || defMsg, each: swagger.isArray }; decorators.push((0, utils_1.Max)(opts.max[0], validatorOption)); swagger.maximum = opts.max[0]; } if ((0, lodash_1.isNumber)(opts.max)) { decorators.push((0, utils_1.Max)(opts.max, { message: defMsg, each: swagger.isArray })); swagger.maximum = opts.max; } } return decorators; } //# sourceMappingURL=number.prop.js.map