EntityProvider
Summary
Defines class EntityProvider.
The EntityProvider offers basic CRUD (Cread Read Update Delete) operations on a collection.
EntityProvider must not be used directly. Use one of its sub class instead.
Each entity model as it's own associated Provider (sub class of EntityProvider).
Constructor
EntityProvider
Syntax
EntityProvider
()
Summary
Example:
// Example for implementing a new EntityProvider named "CustomProvider"
// CustomProvider.js
var util = require('util');
var api = require('@openveo/api');
function CustomProvider(database) {
// Initialize the entity provider with collection "customCollection"
api.EntityProvider.call(this, database, 'customCollection');
}
// CustomProvider must extend EntityProvider
module.exports = CustomProvider;
util.inherits(CustomProvider, api.EntityProvider);
// Example for how to use CustomProvider defined in previous example
var api = require('@openveo/api');
var CustomProvider = process.require('CustomProvider.js');
var provider = new CustomProvider(api.applicationStorage.getDatabase()));
Item Index
Methods
add
Syntax
add
-
data -
[callback]
Summary
Adds a new entity.
get
Syntax
get
-
filter -
callback
Summary
Gets all entities.
getOne
Syntax
getOne
-
id -
filter -
callback
Summary
Gets an entity.
getPaginatedFilteredEntities
Syntax
getPaginatedFilteredEntities
-
[filter] -
[limit] -
[page] -
[sort] -
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
-
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
increase
Syntax
increase
-
id -
data -
callback
Summary
Increase an entity.
If the entity has the property "locked", it won't be increased.
Parameters:
-
idStringThe id of the entity to update
-
dataObjectObject which key is the parameter to increase and value, amount of increase/decrease
- Ex: {views: 56, priority: -5}
-
callbackFunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Number The number of updated items
remove
Syntax
remove
-
ids -
callback
Summary
Removes one or several entities.
If the entity has the property "locked", it won't be removed.
removeProp
Syntax
removeProp
-
property -
callback
Summary
Removes a property on all documents in the collection.
If the entity has the property "locked", it won't be updated.
update
Syntax
update
-
id -
data -
callback
Summary
Updates an entity.
If the entity has the property "locked", it won't be updated.