node-web-mvc
Version:
node spring mvc
35 lines (34 loc) • 1.27 kB
JavaScript
;
/**
* 被注释的元素必须是一个过去的日期
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const UnexpectedTypeException_1 = __importDefault(require("../../errors/UnexpectedTypeException"));
const Target_1 = __importDefault(require("../../servlets/annotations/Target"));
const ElementType_1 = __importDefault(require("../../servlets/annotations/annotation/ElementType"));
const Constraints_1 = __importDefault(require("./Constraints"));
class Past extends Constraints_1.default {
constructor() {
super(...arguments);
this.message = '{validation.constraints.Past.message}';
}
isValid(content, context) {
if (!context.currentTyper.isType(Date)) {
throw new UnexpectedTypeException_1.default(context);
}
const now = Date.now();
return content.getTime() < now;
}
}
/**
* 验证配置元素的值必须是过去的日期
*
* 支持的类型
* - Date
*
* `null` 或者 `undefined` 不做验证
*/
exports.default = (0, Target_1.default)([ElementType_1.default.PROPERTY, ElementType_1.default.PARAMETER])(Past);