EntityModel
Summary
Defines class EntityModel.
The EntityModel provides basic CRUD (Create Read Update Delete) operations on entities.
All entities models must extend EntityModel. EntityModel must not be used directly. Use one of its sub class
instead.
Each entity as it's own associated Model (sub class of EntityModel).
Constructor
EntityModel
Syntax
EntityModel
(
-
provider
Summary
Parameters:
-
providerEntityProviderThe entity provider
Example:
// Example for implementing a new EntityModel named "CustomModel"
// CustomModel.js
var util = require('util');
var api = require('@openveo/api');
var CustomProvider = process.require('CustomProvider.js');
function CustomModel() {
// Initialize the entity model with a dedicated provider
api.EntityModel.call(this, new CustomProvider(api.applicationStorage.getDatabase()));
}
// CustomModel must extends EntityModel
module.exports = CustomModel;
util.inherits(CustomModel, api.EntityModel);
// Example for how to use CustomModel defined in previous example
var api = require('@openveo/api');
var CustomModel = process.require('CustomModel.js');
var model = new CustomModel();
Methods
add
Syntax
add
(
async
-
data -
callback
Summary
Adds a new entity.
get
Syntax
get
(
async
-
filter -
callback
Summary
Gets all entities.
getOne
Syntax
getOne
(
async
-
id -
filter -
callback
Summary
Gets a single entity by its id.
getPaginatedFilteredEntities
Syntax
getPaginatedFilteredEntities
(
async
-
[filter] -
[limit] -
[page] -
[sort] -
[populate] -
callback
Summary
Gets an ordered list of entities by page.
Parameters:
-
[filter]Object optionalMongoDB filter
-
[limit]Number optionalThe maximum number of expected entities
-
[page]Number optionalThe expected page
-
[sort]Object optionalA sort object
-
[populate]Boolean optionaltrue to automatically populate results with additional information
-
callbackFunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Array The list of entities
- Object Pagination information
remove
Syntax
remove
(
async
-
ids -
callback
Summary
Removes one or several entities.
update
Syntax
update
(
async
-
id -
data -
callback
Summary
Updates an entity.