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:
parentInternalOpenGateAPI - this is ogapi instanceroutesobject - 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:
filterFieldstring - 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:
filterFieldstring - This field must be allowed into the specific resourcetypeSortstring
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:
filterFieldstring - 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:
filterFilterBuilder,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:
sizenumber - Defined the number of elements on responsestartnumber (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:
filterFieldstring - 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:
msnumber - timeout in milliseconds
Returns:
SearchBuilder
Example:
ogapi.subscriptionsSearchBuilder().withTimeout(2000)