@decaf-ts/db-decorators
Version:
Agnostic database decorators and repository
38 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpdateValidator = void 0;
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
/**
* @description Abstract base class for validators that compare new values with old values during updates.
* @summary Base class for an Update validator that provides a framework for implementing validation logic that compares a new value with its previous state.
* @param {string} [message] - Error message. Defaults to {@link DecoratorMessages#DEFAULT}
* @param {string[]} [acceptedTypes] - The accepted value types by the decorator
* @class UpdateValidator
* @example
* // Extending UpdateValidator to create a custom validator
* class MyCustomValidator extends UpdateValidator {
* constructor() {
* super("Custom validation failed");
* }
*
* public updateHasErrors(value: any, oldValue: any): string | undefined {
* // Custom validation logic
* if (value === oldValue) {
* return this.message;
* }
* return undefined;
* }
*
* hasErrors(value: any): string | undefined {
* return undefined; // Not used for update validators
* }
* }
* @category Validators
*/
class UpdateValidator extends decorator_validation_1.Validator {
constructor(message = decorator_validation_1.DEFAULT_ERROR_MESSAGES.DEFAULT, ...acceptedTypes) {
super(message, ...acceptedTypes);
}
}
exports.UpdateValidator = UpdateValidator;
//# sourceMappingURL=UpdateValidator.js.map