@allgemein/schema-api
Version:
Library for schema api
34 lines • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IsNotEmpty = IsNotEmpty;
const lodash_1 = require("lodash");
const AnnotationsHelper_1 = require("../../lib/AnnotationsHelper");
const DefaultValidator_1 = require("../../lib/validation/DefaultValidator");
function IsNotEmpty(options) {
return function (source, propertyName) {
const opts = {
validate: 'isNotEmpty'
};
if (options) {
(0, lodash_1.assign)(opts, { validateOptions: { isNotEmpty: {} } });
(0, lodash_1.assign)(opts.validateOptions.isNotEmpty, options);
}
AnnotationsHelper_1.AnnotationsHelper.forPropertyOn(source.constructor, propertyName, opts, 'merge');
};
}
DefaultValidator_1.DefaultValidator.define({
name: 'isNotEmpty',
fn: (value, opts, instance) => {
let res = !((0, lodash_1.isUndefined)(value) || (0, lodash_1.isNull)(value));
if (res) {
if ((0, lodash_1.isString)(value) || (0, lodash_1.isArray)(value)) {
return !(0, lodash_1.isEmpty)(value);
}
}
return res;
},
defaultOptions: {
message: 'Property "%propertyName" must be set and be not empty.'
}
});
//# sourceMappingURL=IsNotEmpty.js.map