Skip to content

Commit 9598402

Browse files
fix: fixed taxonomies url, levels param and added doc
1 parent 5a2574f commit 9598402

File tree

4 files changed

+97
-6
lines changed

4 files changed

+97
-6
lines changed

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const config = {
99
entries: "/entries/",
1010
assets: "/assets/",
1111
environments: "/environments/",
12-
taxonomies: "/taxonomies/"
12+
taxonomies: "/taxonomies/entries"
1313
},
1414
live_preview: {
1515
enable: false,

index.d.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export class Stack {
125125
ContentType(uid: string): ContentType;
126126
Assets(uid: string): Asset;
127127
Assets(): Assets;
128+
Taxonomies(): Taxonomies;
128129

129130
setPort(port: number): Stack;
130131
setProtocol(protocol: string): Stack;
@@ -152,7 +153,14 @@ export class ContentType {
152153
constructor();
153154
content_type_uid: string
154155

155-
Query(): Query;
156+
Query(): TaxonomyQuery;
157+
Entry(uid: string): Entry;
158+
fetch(fetchOptions?: object): Promise<any>;
159+
}
160+
161+
export class Taxonomies {
162+
constructor();
163+
Query(): TaxonomyQuery;
156164
Entry(uid: string): Entry;
157165
fetch(fetchOptions?: object): Promise<any>;
158166
}
@@ -277,3 +285,11 @@ export class Query extends Entry {
277285
find(fetchOptions?: object): Promise<any>;
278286
findOne(): Promise<any>;
279287
}
288+
289+
export class TaxonomyQuery extends Query {
290+
constructor();
291+
above(key: string, value: string, levels?: number): Query;
292+
equalAndAbove(key: string, value: string, levels?: number): Query;
293+
below(key: string, value: string, levels?: number): Query;
294+
equalAndBelow(key: string, value: string, levels?: number): Query;
295+
}

src/core/modules/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function getRequestUrl(type, config, content_type_uid, baseURL) {
9090
url = baseURL + config.urls.assets;
9191
break;
9292
case 'taxonomy':
93-
url = baseURL + config.urls.taxonomies + config.urls.entries;
93+
url = baseURL + config.urls.taxonomies;
9494
break;
9595
case 'contentType':
9696
default:

src/core/modules/taxonomy.js

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import Query from "./query";
33
// Overrideing compare function to include level
44
const _extend = {
55
compare: function(type) {
6-
return function(key, value, level=0) {
6+
return function(key, value, levels) {
77
if (key && value && typeof key === 'string' && typeof value !== 'undefined') {
88
this._query['query'][key] = this._query['query']['file_size'] || {};
99
this._query['query'][key][type] = value;
10-
if (level > 0 && level <= 10) {
11-
this._query['query'][key]['level'] = level
10+
if (levels && typeof levels === "number") {
11+
this._query['query'][key]['levels'] = levels
1212
}
1313
return this;
1414
} else {
@@ -21,9 +21,84 @@ const _extend = {
2121
export default class TaxonomyQuery extends Query {
2222
constructor() {
2323
super();
24+
/**
25+
* @method above
26+
* @memberOf Query
27+
* @description Get all entries for a specific taxonomy that match only the parent term(s) of a specified target term, excluding the target term itself. You can also specify a specific level.
28+
* @param {String} key - uid of the taxonomy, specified as `taxonomies.<taxonomy_uid>`
29+
* @param {*} value - uid of the term to be matched
30+
* @example For taxonomy_uid = taxonomy1, and term_uid = term1
31+
* let blogQuery = Stack().ContentType('example').Query();
32+
* let data = blogQuery.above("taxonomies.taxonomy1", "term1").toJSON().find() // without levels
33+
* let data = blogQuery.above("taxonomies.taxonomy1", "term1", 4).toJSON().find() // with levels
34+
* data.then(function (result) {
35+
* // result = the data which matches only the parent term(s) of the specified term, excluding the term itself
36+
* },function (error) {
37+
* // error function
38+
* })
39+
* @returns {Query}
40+
* @instance
41+
*/
2442
this.above = _extend.compare('$above')
43+
44+
/**
45+
* @method equalAndAbove
46+
* @memberOf Query
47+
* @description Get all entries for a specific taxonomy that match a specific term and all its ancestor terms, requiring only the target term and a specified level.
48+
* @param {String} key - uid of the taxonomy, specified as `taxonomies.<taxonomy_uid>`
49+
* @param {*} value - uid of the term to be matched
50+
* @example For taxonomy_uid = taxonomy1, and term_uid = term1
51+
* let blogQuery = Stack().ContentType('example').Query();
52+
* let data = blogQuery.equalAndAbove("taxonomies.taxonomy1", "term1").toJSON().find() // without levels
53+
* let data = blogQuery.equalAndAbove("taxonomies.taxonomy1", "term1", 4).toJSON().find() // with levels
54+
* data.then(function (result) {
55+
* // result = the data which matches a specific term and all its ancestor terms
56+
* },function (error) {
57+
* // error function
58+
* })
59+
* @returns {Query}
60+
* @instance
61+
*/
2562
this.equalAndAbove = _extend.compare('$eq_above')
63+
64+
/**
65+
* @method below
66+
* @memberOf Query
67+
* @description Get all entries for a specific taxonomy that match all of their descendant terms by specifying only the target term and a specific level.
68+
* @param {String} key - uid of the taxonomy, specified as `taxonomies.<taxonomy_uid>`
69+
* @param {*} value - uid of the term to be matched
70+
* @example For taxonomy_uid = taxonomy1, and term_uid = term1
71+
* let blogQuery = Stack().ContentType('example').Query();
72+
* let data = blogQuery.below("taxonomies.taxonomy1", "term1").toJSON().find() // without levels
73+
* let data = blogQuery.below("taxonomies.taxonomy1", "term1", 4).toJSON().find() // with levels
74+
* data.then(function (result) {
75+
* // result = the data which matches all of the descendant terms.
76+
* },function (error) {
77+
* // error function
78+
* })
79+
* @returns {Query}
80+
* @instance
81+
*/
2682
this.below = _extend.compare('$below')
83+
84+
/**
85+
* @method equalAndBelow
86+
* @memberOf Query
87+
* @description Get all entries for a specific taxonomy that match a specific term and all its descendant terms, requiring only the target term and a specified level.
88+
* @param {String} key - uid of the taxonomy, specified as `taxonomies.<taxonomy_uid>`
89+
* @param {*} value - uid of the term to be matched
90+
* @example For taxonomy_uid = taxonomy1, and term_uid = term1
91+
* let blogQuery = Stack().ContentType('example').Query();
92+
* let data = blogQuery.equalAndBelow("taxonomies.taxonomy1", "term1").toJSON().find() // without levels
93+
* let data = blogQuery.equalAndBelow("taxonomies.taxonomy1", "term1", 4).toJSON().find() // with levels
94+
* data.then(function (result) {
95+
* // result = the data which matches a specific term and all its descendant terms.
96+
* },function (error) {
97+
* // error function
98+
* })
99+
* @returns {Query}
100+
* @instance
101+
*/
27102
this.equalAndBelow = _extend.compare('$eq_below')
28103
}
29104
}

0 commit comments

Comments
 (0)