UNPKG

@decaf-ts/decorator-validation

Version:
69 lines 3.15 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GreaterThanOrEqualValidator = void 0; const Validator_1 = require("./Validator.cjs"); const constants_1 = require("./constants.cjs"); const decorators_1 = require("./decorators.cjs"); const utils_1 = require("./utils.cjs"); const reflection_1 = require("@decaf-ts/reflection"); /** * @summary Greater Than or Equal Validator * * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#GREATER_THAN_OR_EQUAL} * * @class GreaterThanOrEqualValidator * @extends Validator * * @category Validators */ let GreaterThanOrEqualValidator = class GreaterThanOrEqualValidator extends Validator_1.Validator { constructor(message = constants_1.DEFAULT_ERROR_MESSAGES.GREATER_THAN_OR_EQUAL) { super(message); } /** * @summary Validates a model * * @param {string} value * @param {GreaterThanOrEqualValidatorOptions} options * @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings. * * @return {string | undefined} * * @override * @see Validator#hasErrors */ hasErrors(value, options, accessor) { let comparisonPropertyValue; try { comparisonPropertyValue = accessor.getValueFromPath(options[constants_1.ValidationKeys.GREATER_THAN_OR_EQUAL]); } catch (e) { return this.getMessage(e.message || this.message); } try { if (((0, utils_1.isValidForGteOrLteComparison)(value, comparisonPropertyValue) && (0, reflection_1.isEqual)(value, comparisonPropertyValue)) || (0, utils_1.isGreaterThan)(value, comparisonPropertyValue)) return undefined; throw new Error(options.message || this.message); } catch (e) { return this.getMessage(e.message, options.label || options[constants_1.ValidationKeys.GREATER_THAN_OR_EQUAL]); } } }; exports.GreaterThanOrEqualValidator = GreaterThanOrEqualValidator; exports.GreaterThanOrEqualValidator = GreaterThanOrEqualValidator = __decorate([ (0, decorators_1.validator)(constants_1.ValidationKeys.GREATER_THAN_OR_EQUAL), __metadata("design:paramtypes", [String]) ], GreaterThanOrEqualValidator); //# sourceMappingURL=GreaterThanOrEqualValidator.js.map