Manual Reference Source Test
import Query from 'clinical6/src/helpers/Query.js'
public class | source

Query

Helper class representing a Query object that can be passed on to the findDynamicContent method

Test:

Constructor Summary

Public Constructor
public

constructor(resource: String | Content, orderBy: Array, page: Number, perPage: Number, minimal: Boolean, brandRelative: Boolean)

Constructs the Query class

Member Summary

Public Members
public
public
public get
public get
public
public
public
public
public
public set

resource(resource: String | Object): String

public get
public
Private Members
private
private
private

Method Summary

Public Methods
public

addSearchValue(searchValue: String | Number): Query

Adds a search value to search for in the Dynamic Content.

public

Builds a query order ascending order based on the column givenf

public

Clears the array of search values.

public

Builds a query order descending order based on the column given

public

Sets the search mode to 'ends_with'.

public

Executes the search.

public

Sets the min of the filter

public

Sets the max of filter

public

limit(num: Number): Query

Builds a query with limit of how many results to show

public

Creates a filter that would force the search to be case sensitive

public

newFilter(attribute: String): Query

Creates a new filter with the attribute

public

Builds the query to specify the module that will be used to look for favorited contents

public

removeSearchValue(searchValue: String): Query

Removes the provided search value from the array of search values.

public

Sets the search method to 'address'

public

Sets the search method to 'date'.

public

Set the search method to 'location'

public

Sets the search method to 'numeric'.

public

Sets the search method to 'tag'.

public

Sets the search method to 'tag_names'.

public

Sets the search mode to 'search'.

public

Sets the exact latitude value for location search/

public

Sets the exact longitude value for location search.

public

setNeLat(latitude: Number | String): Query

Sets the NE latitude value for location search.

public

setNeLong(longitude: Number | String): Query

Sets the NE longitude value for location search.

public

setNwLong(longitude: Number | String): Query

Sets the NW longitude value for location search.

public

Sets the radius for location search.

public

setResource(resource: Object): Query

Function to pass in a Dynamic Content to search.

public

setSwLat(latitude: Number | String): Query

Sets the SW latitude value for location search

public

setSwLong(longitude: Number | String): Query

Sets the SW longitude value for location search.

public

Sets the exact number to filter by for search by number.

public

Builds the query that returns only the contents that belong to brands the mobile_user/device favorited

public

Builds a query that returns only the minimal attributes specified in the filters

public

Sets the search mode to 'starts_with'.

public

Validates all possible types of all filters in Query for a filter call.

public

Sets the search mode to 'whole_word'.

public

Creates a filter that would force the search to check for whole words

Public Constructors

public constructor(resource: String | Content, orderBy: Array, page: Number, perPage: Number, minimal: Boolean, brandRelative: Boolean) source

Constructs the Query class

Params:

NameTypeAttributeDescription
resource String | Content
  • nullable: false

The type of content it is.

orderBy Array
  • optional
  • default: []

an array objects that define the logic to order the results by

page Number
  • optional
  • default: 0

the page number of the results given

perPage Number
  • optional
  • default: 0

the number of content to return per page

minimal Boolean
  • optional
  • default: false

returns only the filtered attributes specified

brandRelative Boolean
  • optional
  • default: false

returns only the contents that belong to brands the mobile_user/device favorited

Example:

const query = new Query('acronyms')
 .ascending('name')
 .setResource('type')
 .addSearchValue('blue')
 .addSearchValue('green')
 .addSearchValue('red')
 .clearSearchValues()
 .searchByAddressMode()
 .setSwLat('10.0')
 .setSwLong('9.9')
 .setNeLat('9.9')
 .limit(10)
 .showMinimal()
 .showBrandRelative()
 .referenceModule('reference')
 .find();

Public Members

public brandRelative: Boolean source

public case_sensitive: Boolean source

public get filter: Object source

public get filters: Array<Object> source

public minimal: Boolean source

public orderBy: Array source

public page: Number source

public perPage: Number source

public reference_module: String source

public set resource(resource: String | Object): String source

public get resource: String source

public whole_word: Boolean source

Private Members

private _filters: Object[] source

private _id: String source

private _resource: String | Content source

Public Methods

public addSearchValue(searchValue: String | Number): Query source

Adds a search value to search for in the Dynamic Content.

Params:

NameTypeAttributeDescription
searchValue String | Number

the string or number value to add.

Return:

Query

this

public ascending(col: String): Query source

Builds a query order ascending order based on the column givenf

Params:

NameTypeAttributeDescription
col String

the column/attribute to sort by

Return:

Query

this

public clearSearchValues(): Query source

Clears the array of search values.

Return:

Query

this

public descending(col: String): Query source

Builds a query order descending order based on the column given

Params:

NameTypeAttributeDescription
col String

the column/attribute to sort by

Return:

Query

this

public endsWithMode(): Query source

Sets the search mode to 'ends_with'. Searches a Dyanmic Content to find matches that end with the values provided in searchValues.

Return:

Query

this

public find(): Promise<Content[]> source

Executes the search. Prior to calling this method, search values must be added. Additionally, a search method should be set. By default, the search mode will be 'search'.

Return:

Promise<Content[]>

A promise with a list of content.

Example:

const q = new Query('acronyms');
q.find();

public greaterThanOrEqualTo(num: Number): Query source

Sets the min of the filter

Params:

NameTypeAttributeDescription
num Number

number to set min value to

Return:

Query

this

public lessThanOrEqualTo(num: Number | String): Query source

Sets the max of filter

Params:

NameTypeAttributeDescription
num Number | String

number to set max value to

Return:

Query

this

public limit(num: Number): Query source

Builds a query with limit of how many results to show

Params:

NameTypeAttributeDescription
num Number

number of results to show

Return:

Query

this

public makeCaseSensitive(): Query source

Creates a filter that would force the search to be case sensitive

Return:

Query

this

public newFilter(attribute: String): Query source

Creates a new filter with the attribute

Params:

NameTypeAttributeDescription
attribute String

The new attribute of the filter

Return:

Query

this

Example:

const q = new Query('acronyms');
q.searchByLocationMode();  // updates existing current filter
q.newFilter('tag'); // creates entirel new filter entry with the attribute 'tag'

public referenceModule(val: String): Query source

Builds the query to specify the module that will be used to look for favorited contents

Params:

NameTypeAttributeDescription
val String

the string value of the module

Return:

Query

this

public removeSearchValue(searchValue: String): Query source

Removes the provided search value from the array of search values. Throws an error if the provided value is not in the search array.

Params:

NameTypeAttributeDescription
searchValue String

the string value to remove.

Return:

Query

this

public searchByAddressMode(): Query source

Sets the search method to 'address'

Return:

Query

this

public searchByDateMode(): Query source

Sets the search method to 'date'.

Return:

Query

this

public searchByLocationMode(): Query source

Set the search method to 'location'

Return:

Query

this

public searchByNumberMode(): Query source

Sets the search method to 'numeric'.

Return:

Query

this

public searchByTagIDMode(): Query source

Sets the search method to 'tag'.

Return:

Query

this

public searchByTagNamesMode(): Query source

Sets the search method to 'tag_names'.

Return:

Query

this

public searchMode(): Query source

Sets the search mode to 'search'. Searches a Dyanmic Content to find the values in filter.values.

Return:

Query

this

public setExactLatitude(latitude: Number | String): Query source

Sets the exact latitude value for location search/

Params:

NameTypeAttributeDescription
latitude Number | String

number to set exact latitude value to

Return:

Query

this

public setExactLongitude(longitude: Number | String): Query source

Sets the exact longitude value for location search.

Params:

NameTypeAttributeDescription
longitude Number | String

number to set exact longitude value to

Return:

Query

this

public setNeLat(latitude: Number | String): Query source

Sets the NE latitude value for location search.

Params:

NameTypeAttributeDescription
latitude Number | String

number to set NE latitude value to

Return:

Query

this

public setNeLong(longitude: Number | String): Query source

Sets the NE longitude value for location search.

Params:

NameTypeAttributeDescription
longitude Number | String

number to set NE longitude value to

Return:

Query

this

public setNwLong(longitude: Number | String): Query source

Sets the NW longitude value for location search.

Params:

NameTypeAttributeDescription
longitude Number | String

number to set NW longitude value to

Return:

Query

this

public setRadius(radius: Number | String): Query source

Sets the radius for location search.

Params:

NameTypeAttributeDescription
radius Number | String

number to set the radius value to

Return:

Query

this

public setResource(resource: Object): Query source

Function to pass in a Dynamic Content to search. Takes a Dynamic Content response and checks for the 'content_type'.

Params:

NameTypeAttributeDescription
resource Object

Either an object of type Content or a String permanent link value.

Return:

Query

this

Example:

const q = new Query('labs');
q.setResource('acronyms');

public setSwLat(latitude: Number | String): Query source

Sets the SW latitude value for location search

Params:

NameTypeAttributeDescription
latitude Number | String

number to set SW latitude value to

Return:

Query

this

public setSwLong(longitude: Number | String): Query source

Sets the SW longitude value for location search.

Params:

NameTypeAttributeDescription
longitude Number | String

number to set SW longitude value to

Return:

Query

this

public setValue(num: Number): Query source

Sets the exact number to filter by for search by number.

Params:

NameTypeAttributeDescription
num Number

number to filter by

Return:

Query

this

public showBrandRelative(): Query source

Builds the query that returns only the contents that belong to brands the mobile_user/device favorited

Return:

Query

this

public showMinimal(): Query source

Builds a query that returns only the minimal attributes specified in the filters

Return:

Query

this

public startsWithMode(): Query source

Sets the search mode to 'starts_with'. Searches a Dyanmic Content to find matches that start with the values provided in filter.values.

Return:

Query

this

public validate(): Boolean source

Validates all possible types of all filters in Query for a filter call.

Return:

Boolean

True if this is a valid Query

Throw:

Clinical6Error

If missing required parameters or Query fields

Example:

const q = new Query('acronyms');
q.validate();

public wholeWordMode(): Query source

Sets the search mode to 'whole_word'. Searches a Dyanmic Content to find matches that end with the values provided in searchValues.

Return:

Query

this

public wholeWordSearch(): Query source

Creates a filter that would force the search to check for whole words

Return:

Query

this