recime-bot-runtime
Version:
This runtime is intended to run inside a micro-service container with platform specific integration and module interpreter.
59 lines (58 loc) • 2.61 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var validator_1 = require("./validator");
var DateValidator = /** @class */ (function (_super) {
__extends(DateValidator, _super);
function DateValidator() {
return _super !== null && _super.apply(this, arguments) || this;
}
DateValidator.prototype.validate = function (__, vars, args, data) {
var _this = this;
var input = args.text;
var message = data.response[data.index];
var content = message.content;
return new Promise(function (resolve, reject) {
try {
var date = new Date(input).getTime();
if (!date)
return reject(__.text("Please enter a valid date."));
else if (content.validations) {
for (var _i = 0, _a = content.validations; _i < _a.length; _i++) {
var validation = _a[_i];
switch (validation.name) {
case 'inPast': {
if (date > Date.now())
return reject(__.text(validation.message.replace(/\{0\}/ig, validation.value)));
break;
}
case 'inFuture': {
if (date < Date.now())
return reject(__.text(validation.message.replace(/\{0\}/ig, validation.value)));
break;
}
}
}
}
return vars.post(content.variable.replace(/[{}]+/ig, ""), input).then(function () {
delete vars.values['user-input'];
return _this.responder.processResponse(data, vars);
}).then(resolve);
}
catch (ex) {
reject(__.text(ex.message));
}
});
};
return DateValidator;
}(validator_1.Validator));
exports.DateValidator = DateValidator;