Methods
create() → {Promise}
- Source:
Returns:
Returns a promise that resolves when the model has been saved or rejected with the result from
the validate()
call.
- Type
- Promise
delete() → {Promise}
- Source:
Deletes the object from the server.
This will fire a DELETE request to have the object be removed from the system.
Returns:
Resolves when the object was successfully deleted.
- Type
- Promise
getCollectionChildren() → {Array.<any>}
- Source:
This will return the properties that are marked as owner: true
in the schema definition for the model.
Returns:
Returns an array of properties that are owned by the object
- Type
- Array.<any>
getCollectionChildrenPropertyNames() → {Array.<string>}
- Source:
Gets the names of the properties that are collections on the object.
These are usually the properties that contain ModelCollectionProperties.
Returns:
A list of property names that are marked as type COLLECTION
in the schema.
- Type
- Array.<string>
getDirtyChildren() → {Array.<any>}
- Source:
Returns a list of child properties that are marked as dirty. This uses the getCollectionChildren()
method
to retrieve the children properties and then checks if they are marked as dirty.
The method does not check if direct properties are dirty as those are tracked on the Model itself.
Returns:
- Type
- Array.<any>
getDirtyPropertyNames() → {Array.<string>}
- Source:
Returns a list of properties that have been changed.
Returns:
The names of the properties that were changed.
- Type
- Array.<string>
getEmbeddedObjectCollectionPropertyNames() → {Array.<string>}
- Source:
Gets the names of the properties that are embedded objects.
These the properties that are not represented by a different Model, but are just plain objects that are embedded within the current object.
Returns:
A list of property names of embedded objects.
- Type
- Array.<string>
getReferenceProperties() → {Array.<string>}
- Source:
Gets the names of the properties that are references on the object.
These are usually the properties that contain a Model of a different type. (e.g DataElement -> CategoryCombo)
Returns:
A list of property names that are marked as type REFERENCE
in the schema.
- Type
- Array.<string>
hasDirtyChildren() → {boolean}
- Source:
Check if any of the Model's child collections are dirty.
Returns:
True when one of the children is dirty.
- Type
- boolean
isDirty(includeChildren) → {boolean}
- Source:
Check if the model is in a dirty state and is a candidate to be saved.
It will check for direct properties that have been changed and if any of the children have been changed.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
includeChildren |
boolean |
true
|
If set to false only the models direct properties will be checked. |
Returns:
Returns true when the model is in a dirty state.
- Type
- boolean
resetDirtyState() → {ModelBase}
- Source:
Utility method to reset the dirty state of the object.
This is called after a successful save operation was done.
Returns:
Returns itself for potential chaining
- Type
- ModelBase
save() → {Promise}
- Source:
Checks if the model is dirty. When the model is dirty it will check if the values of the model are valid by calling
validate
. If this is correct it will attempt to save the Model to the api.
myModel.save()
.then((message) => console.log(message));
Returns:
Returns a promise that resolves when the model has been saved
or rejects with the result from the validate()
call.
- Type
- Promise
toJSON() → {Object}
- Source:
This method is generally intended to, by default, usefully serialize Model objects during JSON serialization.
This method will take all the properties that are defined on the schema and create an object with the keys and values for those properties. This will remove any circular dependencies that could have occurred otherwise.
Returns:
- Type
- Object
validate() → {Promise}
- Source:
- Deprecated:
- The api now validates the object on save, so doing the additional request to validate the object is not very useful anymore as the validation on POST/PUT is more extensive than the /api/schemas validation.
This will run the validations on the properties which have validations set. Normally these validations are defined through the DHIS2 schema. It will check min/max for strings/numbers etc. Additionally it will run model validations against the schema.
myModel.validate()
.then(myModelStatus => {
if (myModelStatus.status === false) {
myModelStatus.fields.forEach((fieldName) => console.log(fieldName));
}
});
Returns:
Promise that resolves with an object with a status property that represents if the model is valid or not the fields array will return the names of the fields that are invalid.
- Type
- Promise