DataStateValidatorListener

DataStateValidatorListener

new DataStateValidatorListener()

Source:

Methods

beforeRemove(e, callback)

Occurs before removing a data object and validates object state.
Parameters:
Name Type Description
e DataEventArgs | * An object that represents the event arguments passed to this operation.
callback function A callback function that should be called at the end of this operation. The first argument may be an error if any occured.
Source:

beforeSave(e, callback)

Occurs before creating or updating a data object and validates object state.
Parameters:
Name Type Description
e DataEventArgs | * An object that represents the event arguments passed to this operation.
callback function A callback function that should be called at the end of this operation. The first argument may be an error if any occured.
Source:

DataStateValidatorListener

Validates the state of a data object. DataStateValidatorListener is one of the default listeners which are being registered for all data models.

If the target data object belongs to a model which has one or more constraints, it will try to validate object's state against these constraints.

In the following example the process tries to save the favourite color of a user and passes name instead of user's identifier. DataStateValidatorListener will try to find a user based on the unique constraint of User model and then it will try to validate object's state based on the defined unique constraint of UserColor model.


 // #User.json
 ...
 "constraints":[
 {
     "description": "User name must be unique across different records.",
     "type":"unique",
     "fields": [ "name" ]
 }]
 ...
 

 // #UserColor.json
 ...
 "constraints":[
    { "type":"unique", "fields": [ "user", "tag" ] }
 ]
 ...
 

 var userColor = {
        "user": {
            "name":"admin@example.com"
        },
        "color":"#FF3412",
        "tag":"favourite"
    };
 context.model('UserColor').save(userColor).then(function(userColor) {
        done();
    }).catch(function (err) {
        done(err);
    });
 

Constructor

new DataStateValidatorListener()

Source:

Methods

beforeRemove(e, callback)

Occurs before removing a data object and validates object state.
Parameters:
Name Type Description
e DataEventArgs | * An object that represents the event arguments passed to this operation.
callback function A callback function that should be called at the end of this operation. The first argument may be an error if any occured.
Source:

beforeSave(e, callback)

Occurs before creating or updating a data object and validates object state.
Parameters:
Name Type Description
e DataEventArgs | * An object that represents the event arguments passed to this operation.
callback function A callback function that should be called at the end of this operation. The first argument may be an error if any occured.
Source: