Class: EntityController

controllers/EntityController~EntityController()

EntityController

Constructor

new EntityController()

Defines base controller for all controllers which need to provide HTTP route actions for all requests relative to entities.

Source:

Extends

Methods

addEntitiesAction(request, response, next)

Adds entities.

Parameters:
Name Type Description
request Object

ExpressJS HTTP Request

Properties
Name Type Description
body Array

The list of entities to add with for each entity the fields with their values

response Object

ExpressJS HTTP Response

next function

Function to defer execution to the next registered middleware

Source:
Example
// Response example
{
  "entities": [ ... ],
  "total": 42
}

getEntitiesAction(request, response, next)

Gets entities.

Parameters:
Name Type Description
request Object

ExpressJS HTTP Request

Properties
Name Type Attributes Description
query Object <optional>

Request query

Properties
Name Type Attributes Description
include String | Array <optional>

The list of fields to include from returned entities

exclude String | Array <optional>

The list of fields to exclude from returned entities. Ignored if include is also specified.

limit Number <optional>

A limit number of entities to retrieve per page (default to 10)

page Number <optional>

The page number started at 0 for the first page (default to 0)

sortBy String <optional>

The entity field to sort by

sortOrder String <optional>

Either "asc" for ascendant or "desc" for descendant

response Object

ExpressJS HTTP Response

next function

Function to defer execution to the next registered middleware

Source:
Example
// Response example
{
  "entities" : [ ... ],
  "pagination" : {
    "limit": ..., // The limit number of entities by page
    "page": ..., // The actual page
    "pages": ..., // The total number of pages
    "size": ... // The total number of entities
}

getEntityAction(request, response, next)

Gets a specific entity.

Parameters:
Name Type Description
request Object

ExpressJS HTTP Request

Properties
Name Type Description
params Object

Request parameters

Properties
Name Type Description
id String

The entity id to retrieve

query Object

Request query

Properties
Name Type Attributes Description
include String | Array <optional>

The list of fields to include from returned entity

exclude String | Array <optional>

The list of fields to exclude from returned entity. Ignored if include is also specified.

response Object

ExpressJS HTTP Response

next function

Function to defer execution to the next registered middleware

Source:
Example
// Response example
{
  "entity" : { ... }
}

getProvider() → {EntityProvider}

Gets an instance of the entity provider associated to the controller.

Source:
Throws:

getProvider not implemented for this EntityController

Type
Error
Returns:

The entity provider

Type
EntityProvider

removeEntitiesAction(request, response, next)

Removes entities.

Parameters:
Name Type Description
request Object

ExpressJS HTTP Request

Properties
Name Type Description
params Object

Request parameters

Properties
Name Type Description
id String

A comma separated list of entity ids to remove

response Object

ExpressJS HTTP Response

next function

Function to defer execution to the next registered middleware

Source:
Example
// Response example
{
  "total": 42
}

updateEntityAction(request, response, next)

Updates an entity.

Parameters:
Name Type Description
request Object

ExpressJS HTTP Request

Properties
Name Type Description
params Object

Request parameters

Properties
Name Type Description
id String

The id of the entity to update

body Object

The fields to update with their values

response Object

ExpressJS HTTP Response

next function

Function to defer execution to the next registered middleware

Source:
Example
// Response example
{
  "total": 1
}