Constructor
# new UpdateValidator(messageopt, acceptedTypesopt)
Base class for an Update validator that provides a framework for implementing validation logic that compares a new value with its previous state.
Abstract base class for validators that compare new values with old values during updates.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
message |
string
|
<optional> |
Error message. Defaults to |
acceptedTypes |
Array.<string>
|
<optional> |
The accepted value types by the decorator |
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
}
}
Methods
# abstract updateHasErrors(value, oldValue, args) → {string|undefined}
Validates a value by comparing it to its old version to determine if the update is valid.
Abstract method that must be implemented by subclasses to perform update validation.
Parameters:
Name | Type | Description |
---|---|---|
value |
any
|
The new value to validate |
oldValue |
any
|
The previous value to compare against |
args |
Array.<any>
|
Additional arguments that may be needed for validation |
An error message if validation fails, undefined if validation passes
string
|
undefined