Query
Helper class representing a Query object that can be passed on to the findDynamicContent method
Test:
- [unit] Query should exist
- [unit] Query should throw an error if orderBy are incorrect
- [unit] Query should be able to be constructed properly
- [unit] Query should have all the query methods available
- [unit] Query should have methods that are chain-able
- [unit] Query should create a query with ascending order
- [unit] Query should create a query with descending order
- [unit] Query should create a query with page and perpage when limit is called
- [unit] Query should create a query with brandRelative
- [unit] Query should create a query with minimal
- [unit] Query should create a query with referenceModule
- [unit] Query should create a query with content
- [unit] Query should add search values
- [unit] Query should remove search values
- [unit] Query should clear search values
- [unit] Query should set attribute to search
- [unit] Query should set attribute to tag
- [unit] Query should set searchMethod to starts_with
- [unit] Query should set searchMethod to ends_with
- [unit] Query should set searchMethod to whole_word
- [unit] Query should set whole_word to true
- [unit] Query should set case_sensitive to true
- [unit] Query should set a radius value
- [unit] Query should set the exact latitude value
- [unit] Query should set the exact longitude value
- [unit] Query should set SW Latitude value
- [unit] Query should set SW Longitude value
- [unit] Query should set NE Latitude value
- [unit] Query should set NW Longitutde value
- [unit] Query should set a value
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 |
|
|
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 |
descending(col: String): Query Builds a query order descending order based on the column given |
|
public |
Sets the search mode to 'ends_with'. |
|
public |
Executes the search. |
|
public |
greaterThanOrEqualTo(num: Number): Query Sets the min of the filter |
|
public |
lessThanOrEqualTo(num: Number | String): Query Sets the max of filter |
|
public |
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 |
Creates a new filter with the attribute |
|
public |
referenceModule(val: String): Query 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 |
searchMode(): Query Sets the search mode to 'search'. |
|
public |
setExactLatitude(latitude: Number | String): Query Sets the exact latitude value for location search/ |
|
public |
setExactLongitude(longitude: Number | String): Query Sets the exact longitude value for location search. |
|
public |
Sets the NE latitude value for location search. |
|
public |
Sets the NE longitude value for location search. |
|
public |
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 |
Sets the SW latitude value for location search |
|
public |
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 |
showMinimal(): Query 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:
Name | Type | Attribute | Description |
resource | String | Content |
|
The type of content it is. |
orderBy | Array |
|
an array objects that define the logic to order the results by |
page | Number |
|
the page number of the results given |
perPage | Number |
|
the number of content to return per page |
minimal | Boolean |
|
returns only the filtered attributes specified |
brandRelative | Boolean |
|
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
Private Members
Public Methods
public addSearchValue(searchValue: String | Number): Query source
Adds a search value to search for in the Dynamic Content.
Params:
Name | Type | Attribute | Description |
searchValue | String | Number | the string or number value to add. |
public ascending(col: String): Query source
Builds a query order ascending order based on the column givenf
Params:
Name | Type | Attribute | Description |
col | String | the column/attribute to sort by |
public descending(col: String): Query source
Builds a query order descending order based on the column given
Params:
Name | Type | Attribute | Description |
col | String | the column/attribute to sort by |
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.
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'.
Example:
const q = new Query('acronyms');
q.find();
public greaterThanOrEqualTo(num: Number): Query source
Sets the min of the filter
Params:
Name | Type | Attribute | Description |
num | Number | number to set min value to |
public limit(num: Number): Query source
Builds a query with limit of how many results to show
Params:
Name | Type | Attribute | Description |
num | Number | number of results to show |
public makeCaseSensitive(): Query source
Creates a filter that would force the search to be case sensitive
public newFilter(attribute: String): Query source
Creates a new filter with the attribute
Params:
Name | Type | Attribute | Description |
attribute | String | The new attribute of the filter |
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:
Name | Type | Attribute | Description |
val | String | the string value of the module |
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:
Name | Type | Attribute | Description |
searchValue | String | the string value to remove. |
public searchMode(): Query source
Sets the search mode to 'search'. Searches a Dyanmic Content to find the values in filter.values.
public setExactLatitude(latitude: Number | String): Query source
Sets the exact latitude value for location search/
public setExactLongitude(longitude: Number | String): Query source
Sets the exact longitude value for location search.
public setNeLat(latitude: Number | String): Query source
Sets the NE latitude value for location search.
public setNeLong(longitude: Number | String): Query source
Sets the NE longitude value for location search.
public setNwLong(longitude: Number | String): Query source
Sets the NW longitude value for location search.
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:
Name | Type | Attribute | Description |
resource | Object | Either an object of type Content or a String permanent link value. |
Example:
const q = new Query('labs');
q.setResource('acronyms');
public setSwLat(latitude: Number | String): Query source
Sets the SW latitude value for location search
public setSwLong(longitude: Number | String): Query source
Sets the SW longitude value for location search.
public setValue(num: Number): Query source
Sets the exact number to filter by for search by number.
Params:
Name | Type | Attribute | Description |
num | Number | number to filter by |
public showBrandRelative(): Query source
Builds the query that returns only the contents that belong to brands the mobile_user/device favorited
public showMinimal(): Query source
Builds a query that returns only the minimal attributes specified in the filters
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.
public validate(): Boolean source
Validates all possible types of all filters in Query for a filter call.
Throw:
If missing required parameters or Query fields |
Example:
const q = new Query('acronyms');
q.validate();