Skip to content

Commit cd8284a

Browse files
author
Ali Tahir
committed
added documentation for all types and enums
1 parent fc509d8 commit cd8284a

File tree

6 files changed

+99
-11
lines changed

6 files changed

+99
-11
lines changed

src/methods/getContentList.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
99
* @param {number} [requestParams.take] - The maximum number of items to retrieve in this request. Default is **10**. Maximum allowed is **50**.
1010
* @param {number} [requestParams.skip] - The number of items to skip from the list. Default is **0**. Used for implementing pagination.
1111
* @param {string} [requestParams.sort] - The field to sort the results by. Example *fields.title* or *properties.created*.
12-
* @param {string} [requestParams.direction] - The direction to sort the results by. Default is **asc**. Valid values are **asc**, **desc**.
13-
* @param {Array} [requestParams.filters] - The collection of filters to filter the results by. A filter object contains properties called **property**, **operator**, **value**. Operators can be **eq** Equal To, **ne** Not Equal To, **gt** Greater Than, **gte** Greater Than or Equal To, **lt * @param {Array} [requestParams.filters] - The collection of filters to filter the results by. A filter object contains properties called **property**, **operator**, **value**. Operators can be **eq** Equal To, **ne** Not Equal To, **gt** Greater Than, **gte** Greater Than or Equal To, **lt** Less Than, **lte** Less Than or Equal To, **like** Like (string only)
14-
* @param (string) [requestParams.filtersLogicOperator] - The logic operator to combine multiple filters. **AND** (default), **OR**.
12+
* @param {AgilityFetch.Types.SortDirection} [requestParams.direction] - The direction to sort the results by.
13+
* @param {Array.<AgilityFetch.Types.Filter>} [requestParams.filters] - The collection of filters to filter the results by.
14+
* @param {AgilityFetch.Types.FilterLogicOperator} [requestParams.filtersLogicOperator] - The logic operator to combine multiple filters.
1515
* @returns {Promise<AgilityFetch.Types.ContentList>} - Returns a list of content items.
1616
* @example
1717
*
1818
* import agility from '@agility/content-fetch'
19+
* import types from ''
1920
*
2021
* const api = agility.getApi({
2122
* guid: '191309ca-e675-4be2-bb29-351879528707',
@@ -28,7 +29,7 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
2829
* take: 50,
2930
* skip: 0,
3031
* sort: 'properties.created',
31-
* direction: 'asc'
32+
* direction: SortDirections.Asc
3233
* })
3334
* .then(function(contentList) {
3435
* console.log(contentList);

src/types/Filter.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Defines a **Filter** for filtering lists.
3+
* @typedef Filter
4+
* @memberof AgilityFetch.Types
5+
* @property {string} property - The property to filter the request on.
6+
* @property {AgilityFetch.Types.FilterOperator} operator - The operator to use for the filter.
7+
* @property {string} value - The value to compare for the property.
8+
*/
9+
10+
11+
12+
13+

src/types/FilterLogicOperator.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Defines a FilterLogicOperator - Refer to {@link AgilityFetch.Types.FilterLogicOperators} Enum for available Logic Operators.
3+
* @typedef {string} FilterLogicOperator
4+
* @memberOf AgilityFetch.Types
5+
*/
6+
7+
/**
8+
* Enum of FilterLogicOperators.
9+
* @enum {FilterLogicOperator} FilterLogicOperators
10+
* @memberOf AgilityFetch.Types
11+
* @default AND
12+
* @readonly
13+
*/
14+
const FilterLogicOperators = {
15+
/** And */
16+
AND: "and",
17+
/** Or */
18+
OR: "or"
19+
};
20+
21+
export default FilterLogicOperators;

src/types/FilterOperator.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Defines a FilterOperator - Refer to {@link AgilityFetch.Types.FilterOperators} Enum for available Operators.
3+
* @typedef {string} FilterOperator
4+
* @memberOf AgilityFetch.Types
5+
*/
6+
7+
/**
8+
* Enum of FilterOperators.
9+
* @enum {FilterOperator} FilterOperators
10+
* @memberOf AgilityFetch.Types
11+
* @readonly
12+
*/
13+
const FilterOperators = {
14+
/** Equal To */
15+
EQUAL_TO: "eq",
16+
/** Not Equal To */
17+
NOT_EQUAL_TO: "ne",
18+
/** Less Than */
19+
LESS_THAN: "lt",
20+
/** Less Than or Equal To */
21+
LESS_THAN_OR_EQUAL_TO: "lte",
22+
/** Greater Than */
23+
GREATER_THAN: "gt",
24+
/** Greater Than or Equal To */
25+
GREATER_THAN_OR_EQUAL_TO: "gte",
26+
/** Like (string only) */
27+
LIKE: "like"
28+
};
29+
30+
export default FilterOperators;

src/types/SortDirection.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Defines a Sort Direction - Refer to {@link AgilityFetch.Types.SortDirections} Enum for available Sort Directions.
3+
* @typedef {string} SortDirection
4+
* @memberOf AgilityFetch.Types
5+
*/
6+
7+
/**
8+
* Enum of SortDirections.
9+
* @enum {SortDirection} SortDirections
10+
* @memberOf AgilityFetch.Types
11+
* @default ASC
12+
* @readonly
13+
*/
14+
const SortDirections = {
15+
/** Ascending */
16+
ASC: "asc",
17+
/** Descending */
18+
DESC: "desc",
19+
};
20+
21+
export default SortDirections;

test/getContentList.tests.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import chai from 'chai'
22
const assert = chai.assert;
33
const expect = chai.expect;
4-
4+
import { FilterOperators } from '../src/types/FilterOperator';
5+
import { SortDirections } from '../src/types/SortDirection';
6+
import { FilterLogicOperators } from '../src/types/FilterLogicOperator';
57
import { createApiClient, createPreviewApiClient, createCatchedApiClient } from './apiClients.config'
68

79
/*
@@ -190,7 +192,7 @@ describe('getContentList:', function() {
190192
referenceName: 'posts',
191193
languageCode: 'en-us',
192194
sort: 'properties.versionID',
193-
direction: 'desc'
195+
direction: SortDirections.DESC
194196
})
195197
.then(function(contentList) {
196198
assert.strictEqual(contentList.items[0].contentID, 16);
@@ -206,7 +208,7 @@ describe('getContentList:', function() {
206208
api.getContentList({
207209
referenceName: 'posts',
208210
languageCode: 'en-us',
209-
filters: [{operator: 'eq', value: '40'}]
211+
filters: [{operator: FilterOperators.EQUAL_TO, value: '40'}]
210212
})
211213
.then(function(contentList) {
212214
done();
@@ -238,7 +240,7 @@ describe('getContentList:', function() {
238240
api.getContentList({
239241
referenceName: 'posts',
240242
languageCode: 'en-us',
241-
filters: [{property: 'properties.versionID', operator: 'eq'}]
243+
filters: [{property: 'properties.versionID', operator: FilterOperators.EQUAL_TO}]
242244
})
243245
.then(function(contentList) {
244246
done();
@@ -285,8 +287,8 @@ describe('getContentList:', function() {
285287
api.getContentList({
286288
referenceName: 'posts',
287289
languageCode: 'en-us',
288-
filters: [{property: 'properties.versionID', operator: 'eq', value: '40'}, {property: 'properties.referenceName', operator: 'like', value: 'posts'}],
289-
filtersLogicOperator: 'OR'
290+
filters: [{property: 'properties.versionID', operator: FilterOperators.EQUAL_TO, value: '40'}, {property: 'properties.referenceName', operator: FilterOperators.LIKE, value: 'posts'}],
291+
filtersLogicOperator: FilterLogicOperators.OR
290292
})
291293
.then(function(contentList) {
292294
assert.strictEqual(contentList.items[0].contentID, 15);
@@ -301,7 +303,7 @@ describe('getContentList:', function() {
301303
api.getContentList({
302304
referenceName: 'posts',
303305
languageCode: 'en-us',
304-
filters: [{property: 'properties.versionID', operator: 'eq', value: '40'}, {property: 'properties.referenceName', operator: 'like', value: 'posts'}]
306+
filters: [{property: 'properties.versionID', operator: FilterOperators.EQUAL_TO, value: '40'}, {property: 'properties.referenceName', operator: FilterOperators.LIKE, value: 'posts'}]
305307
})
306308
.then(function(contentList) {
307309
assert.strictEqual(contentList.items[0].contentID, 16);

0 commit comments

Comments
 (0)