API Docs for: 0.8.0
Show:

TopicService Class

Provides interactions with topics

Constructor

TopicService

(
  • context
)

Parameters:

  • context Object

Methods

_emit

(
  • event
  • data
  • cb
)
protected

Parameters:

  • event String
  • data Object
  • cb Function

_get

(
  • id
  • [options]
  • cb
)
protected

Parameters:

  • id String
  • [options] Object optional
  • cb Function

_retrieveOnUpdateAndMerge

(
  • dto
  • options
  • cb
)
private
When an ID is available in the DTO the function attempts to retrieve the existing object. If it is not available a new object is created. The merge event is then called. After the merge is complete the callback is executed with the merged object.

Parameters:

  • dto Object
  • options Object
    • [isCreate] Boolean optional
  • cb Function

add

(
  • dto
  • [options]
  • cb
)
Attempts to persist the DTO as an add. The function executes a series of events: 1) The format event is fired 2) When an ID is provided the object is retrieved from the database otherwise a new object is created. 3) The merge event is triggered 4) The validate event is triggered. If validation errors are detected the process halts and the function calls back with an error. 5) The beforeSave event is triggered 6) The object is persisted 7) The afterSave event is triggered

Parameters:

  • dto Object
  • [options] Object optional
  • cb Function
    A callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query

count

(
  • [options]
  • cb
)
Executes a count of resources against the persistence layer. The function will callback with an array of results.

Parameters:

  • [options] Object optional
    • [where] Object optional
  • cb Function
    A callback that takes two parameters. The first is an error, if occurred. The second is the number of results that match the specified query

deleteById

(
  • id
  • options
  • cb
)
Deletes an object by ID

Parameters:

  • id String
  • options Object
  • cb Function

deleteSingle

(
  • [options]
  • cb
)
Deletes a single item based on the specified query in the options

Parameters:

  • [options] Object optional
    See BaseObjectService#getSingle
    • [where] Object optional
  • cb Function

format

(
  • context
  • cb
)
static

Parameters:

  • context Object
    • service TopicService

      An instance of the service that triggered the event that called this handler

  • cb Function

    A callback that takes a single parameter: an error if occurred

get

(
  • id
  • [options]
  • cb
)
Retrieves a resource by ID. The function will callback with the object that was found or NULL if no object could be found. The function will trigger the "get" event.

Parameters:

  • id String
  • [options] Object optional
  • cb Function

    (Error, object|null) A callback that takes two parameters. The first is an error, if occurred. The second is the object with the specified ID

getAll

(
  • [options]
  • cb
)
Executes a query for resources against the persistence layer. The function will callback with an array of results. The function will trigger the "getAll" event. Also note that there is hard limit on the number of results the returned.

Parameters:

  • [options] Object optional
    • [select] Object optional
    • [where] Object optional
    • [order] Array optional
    • [limit] Integer optional
    • [offset] Integer optional
  • cb Function

    A callback that takes two parameters. The first is an error, if occurred. The second is an array representing the results of the query.

getAllWithCount

(
  • [options]
  • cb
)
Executes a query for resources against the persistence layer. The function will callback with an object that contains a total count and an array of results. The function will trigger the "getAll" event. Also note that there is hard limit on the number of results the returned.

Parameters:

  • [options] Object optional
    • [select] Object optional
    • [where] Object optional
    • [order] Array optional
    • [limit] Integer optional
    • [offset] Integer optional
  • cb Function
    A callback that takes two parameters. The first is an error, if occurred. The second is an object representing the results of the query.

getContext

(
  • [data]
)
Object
Retrieves a context object to be passed to event listeners

Parameters:

  • [data] String | Object | Number | Boolean optional

Returns:

Object:

getIdWhere

(
  • dto
)
Object
Creates the where clause that creates a lookup by the key that indicates uniqueness for the collection

Parameters:

  • dto Object

Returns:

Object:

getSingle

(
  • [options]
  • cb
)
Retrieves a single resource by the specified query. The function will callback with the object that was found or NULL if no object could be found. The function will trigger the "getAll" event.

Parameters:

  • [options] Object optional
    • [select] Object optional
    • [where] Object optional
    • [order] Array optional
    • [offset] Integer optional
  • cb Function

    A callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query

getType

() String
Retrieves the object type supported by the service

Returns:

String: The object type supported

merge

(
  • context
  • cb
)
static

Parameters:

  • context Object
    • service TopicService

      An instance of the service that triggered the event that called this handler

  • cb Function

    A callback that takes a single parameter: an error if occurred

save

(
  • dto
  • [options]
  • cb
)
Attempts to persist the DTO. The function executes a series of events: 1) The format event is fired 2) When an ID is provided the object is retrieved from the database otherwise a new object is created. 3) The merge event is triggered 4) The validate event is triggered. If validation errors are detected the process halts and the function calls back with an error. 5) The beforeSave event is triggered 6) The object is persisted 7) The afterSave event is triggered

Parameters:

  • dto Object
  • [options] Object optional
    • [isCreate] Boolean optional
  • cb Function
    A callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query

update

(
  • dto
  • [options]
  • cb
)
Attempts to persist the DTO as an update. The function executes a series of events: 1) The format event is fired 2) When an ID is provided the object is retrieved from the database otherwise a new object is created. 3) The merge event is triggered 4) The validate event is triggered. If validation errors are detected the process halts and the function calls back with an error. 5) The beforeSave event is triggered 6) The object is persisted 7) The afterSave event is triggered

Parameters:

  • dto Object
  • [options] Object optional
  • cb Function
    A callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query

validate

(
  • context
  • cb
)
static

Parameters:

  • context Object
    • data Object

      The DTO that was provided for persistence

    • service TopicService

      An instance of the service that triggered the event that called this handler

  • cb Function

    A callback that takes a single parameter: an error if occurred

Properties

dao

DAO
An instance of DAO to be used to interact with the persistence layer

TYPE

String private static

type

String
Represents the name of the collection to interact with