OpenVeo server API for plugins

API Docs for: 3.0.0
Show:

EntityModel

Module: models

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:

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

(
  • data
  • callback
)
async

Summary

Adds a new entity.

Parameters:

  • data Object

    Entity data to store into the collection, its structure depends on the type of entity

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Number The total amount of items inserted
    • Object The added entity

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 a single entity by its id.

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]
  • [populate]
  • 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

  • [populate] Boolean optional

    true to automatically populate results with additional information

  • 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

remove

Syntax

remove

(
  • ids
  • callback
)
async

Summary

Removes one or several entities.

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

update

Syntax

update

(
  • id
  • data
  • callback
)
async

Summary

Updates an entity.

Parameters:

  • id String

    The id of the entity to update

  • data Object

    Entity data, its structure depends on the type of entity

  • 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