OpenVeo server API for plugins

API Docs for: 3.0.0
Show:

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()));

Methods

add

Syntax

add

(
  • data
  • [callback]
)
async

Summary

Adds a new entity.

Parameters:

  • data Object

    Data to store into the collection, its structure depends on the entity type

  • [callback] Function optional

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Number The total amount of documents inserted
    • Array All the documents inserted

get

Syntax

get

(
  • filter
  • callback
)
async

Summary

Gets all entities.

Parameters:

  • filter Object

    A MongoDB filter

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Array The list of entities

getOne

Syntax

getOne

(
  • id
  • filter
  • callback
)
async

Summary

Gets an entity.

Parameters:

  • id String

    The entity id

  • filter Object

    A MongoDB filter

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Object The entity

getPaginatedFilteredEntities

Syntax

getPaginatedFilteredEntities

(
  • [filter]
  • [limit]
  • [page]
  • [sort]
  • callback
)
async

Summary

Gets an ordered list of entities by page.

Parameters:

  • [filter] Object optional

    MongoDB filter

  • [limit] Number optional

    The maximum number of expected entities

  • [page] Number optional

    The expected page

  • [sort] Object optional

    A sort object

  • callback Function

    The 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
)
async

Summary

Increase an entity.

If the entity has the property "locked", it won't be increased.

Parameters:

  • id String

    The id of the entity to update

  • data Object

    Object which key is the parameter to increase and value, amount of increase/decrease

    • Ex: {views: 56, priority: -5}
  • callback Function

    The 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
)
async

Summary

Removes one or several entities.

If the entity has the property "locked", it won't be removed.

Parameters:

  • ids String | Array

    Id(s) of the document(s) to remove from the collection

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Number The number of deleted entities

removeProp

Syntax

removeProp

(
  • property
  • callback
)
async

Summary

Removes a property on all documents in the collection.

If the entity has the property "locked", it won't be updated.

Parameters:

  • property String

    The property name to remove

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Number The number of modified entities

update

Syntax

update

(
  • id
  • data
  • callback
)
async

Summary

Updates an entity.

If the entity has the property "locked", it won't be updated.

Parameters:

  • id String

    The id of the entity to update

  • data Object

    Entity data, its structure depends on the entity type

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Number The number of updated items