@decaf-ts/db-decorators
Version:
Agnostic database decorators and repository
51 lines (50 loc) • 2.18 kB
JavaScript
;
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.TimestampValidator = void 0;
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
const constants_1 = require("../constants.cjs");
/**
* @summary Validates the update of a timestamp
*
* @class TimestampValidator
* @extends Validator
*
* @category Validators
*/
let TimestampValidator = class TimestampValidator extends decorator_validation_1.Validator {
constructor() {
super(constants_1.DEFAULT_ERROR_MESSAGES.TIMESTAMP.INVALID);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
hasErrors(value, ...args) {
return undefined;
}
updateHasErrors(value, oldValue, message) {
if (value === undefined)
return;
message = message || this.getMessage(message || this.message);
try {
value = new Date(value);
oldValue = new Date(oldValue);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
}
catch (e) {
return message;
}
return value <= oldValue ? message : undefined;
}
};
exports.TimestampValidator = TimestampValidator;
exports.TimestampValidator = TimestampValidator = __decorate([
(0, decorator_validation_1.validator)(constants_1.UpdateValidationKeys.TIMESTAMP),
__metadata("design:paramtypes", [])
], TimestampValidator);