Search Builder

SearchBuilder

SearchBuilder Objects

class SearchBuilder()

This is a abstract class. It is a base to make all kind of search request to OpenGate North API.

constructor
function constructor()

Constructor

Arguments:

  • parent InternalOpenGateAPI - this is ogapi instance
  • routes object - this defined the routes. One of those routes must be called on Builder before call build method.

[route]
function [route]()

addSortAscendingBy
function addSortAscendingBy(filterField: string) -> 'SearchBuilder'

Add ascending param into the sort search object

Arguments:

  • filterField string - This field must be allowed into the specific resource

Returns:

  • SearchBuilder

Example:

 ogapi.subscriptionsSearchBuilder().addSortAscendingBy('prov.customid') // Order by prov.customid Ascending  

addSortBy
function addSortBy(filterField: string,typeSort: string) -> 'SearchBuilder'

Add ascending/descending param into the sort search object

Arguments:

  • filterField string - This field must be allowed into the specific resource
  • typeSort string

Returns:

  • SearchBuilder

Example:

 ogapi.subscriptionsSearchBuilder().addSortBy('prov.customid','ASCENDING') // Order by prov.customid Ascending
 ogapi.devicesSearchBuilder().addSortBy('prov.customid','DESCENDING') // Order by prov.customid Descending 

addSortDescendingBy
function addSortDescendingBy(filterField: string) -> 'SearchBuilder'

Add descending param into the sort search object

Arguments:

  • filterField string - This field must be allowed into the specific resource

Returns:

  • SearchBuilder

Example:

 ogapi.devicesSearchBuilder().addSortDescendingBy('prov.customid') // Order by prov.customid Descending

build
function build() -> 'Search'

Build a instance of Search

Returns:

  • Search

Example:

 ogapi.devicesSearchBuilder().onProvisioned().build()

filter
function filter(filter: FilterBuilder,object) -> 'SearchBuilder'

The search request will have this filter

Arguments:

  • filter FilterBuilder,object

Returns:

  • SearchBuilder

Example:

 ogapi.subscriptionsSearchBuilder().filter(
     ogapi.newFilterBuilder().and(Ex.like('prov.customid', 'SN32'), Ex.neq('entityId', '1124'))
 ) // Setting FilterBuilder
 ogapi.subscriptionsSearchBuilder().filter(
      {"and": [{"like": {"entityId": "0000000000000001"}}]}
 ) // Custom filter

findAllFields
function findAllFields(input: *) -> 'Promise'

Return a promise which it will contains an array with fields recommended with complete structure

Arguments:

  • input *

Returns:

  • Promise

findFieldPath
function findFieldPath(field: *) -> 'Promise'

Return a promise which it will contains an string with the path of a field

Arguments:

  • field *

Returns:

  • Promise

findFields
function findFields(input: *) -> 'Promise'

Return a promise which it will contains an array with fields recommended with only identifier

Arguments:

  • input *

Returns:

  • Promise

limit
function limit(size: number,start: number) -> 'SearchBuilder'

Set reponse pagination.

Arguments:

  • size number - Defined the number of elements on response
  • start number (optional) - Defined the offset on response

Returns:

  • SearchBuilder

Example:

 ogapi.subscribersSearchBuilder().limit(10) // Without offset
 ogapi.subscribersSearchBuilder().limit(25,50) //With offset value 50

removeSortBy
function removeSortBy(filterField: string) -> 'SearchBuilder'

Remove sort param from the search object

Arguments:

  • filterField string - This field must be allowed into the specific resource

Returns:

  • SearchBuilder

Example:

 ogapi.subscriptionsSearchBuilder().removeSortBy('prov.customid') // Remove order by prov.customid
 ogapi.subscriptionsSearchBuilder().removeSortBy() // Remove all order by parameters

withTimeout
function withTimeout(ms: number) -> 'SearchBuilder'

The request will have a specific time out if it will be exceeded then the promise throw an exception

Arguments:

  • ms number - timeout in milliseconds

Returns:

  • SearchBuilder

Example:

 ogapi.subscriptionsSearchBuilder().withTimeout(2000)