Skip to content

Commit 5d041f3

Browse files
feat: added taxonomies url
1 parent fbfb8e8 commit 5d041f3

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
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-
taxonomy: "/taxonomies/"
12+
taxonomies: "/taxonomies/"
1313
},
1414
live_preview: {
1515
enable: false,

src/core/modules/query.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ const _extend = {
7777
}
7878
};
7979

80+
/**
81+
* @function getRequestUrl
82+
* @description Returns host url based on this.type
83+
* @param {Object} this `this` variable from Query class
84+
* @return {string} returns the url that will be used to make API calls
85+
*/
86+
function getRequestUrl(this, baseURL) {
87+
switch(this.type) {
88+
case 'asset':
89+
url = baseURL + this.config.urls.assets;
90+
break;
91+
case 'taxonomy':
92+
url = baseURL + this.config.urls.taxonomies + this.config.urls.entries;
93+
break;
94+
case 'contentType':
95+
default:
96+
url = baseURL + this.config.urls.content_types + this.content_type_uid + this.config.urls.entries;
97+
break;
98+
}
99+
return url;
100+
}
101+
80102
/**
81103
* @class
82104
Query
@@ -400,6 +422,7 @@ export default class Query extends Entry {
400422
}
401423

402424
/**
425+
* @method where
403426
* @memberOf Query
404427
* @description Retrieve entries in which a specific field satisfies the value provided
405428
* @param {String} key - uid of the field
@@ -441,7 +464,7 @@ export default class Query extends Entry {
441464
*/
442465
count() {
443466
const host = this.config.protocol + "://" + this.config.host + ':' + this.config.port + '/' + this.config.version,
444-
url = (this.type && this.type === 'asset') ? host + this.config.urls.assets : host + this.config.urls.content_types + this.content_type_uid + this.config.urls.entries;
467+
url = getRequestUrl(this, host);
445468
this._query['count'] = true;
446469
this.requestParams = {
447470
method: 'POST',
@@ -750,8 +773,10 @@ export default class Query extends Entry {
750773
if (this.type && this.type !== 'asset' && this.live_preview && this.live_preview.enable === true && this.live_preview.content_type_uid === this.content_type_uid ) {
751774
host = this.live_preview.host;
752775
}
753-
const baseURL = this.config.protocol + "://" + host + '/' + this.config.version,
754-
url = (this.type && this.type === 'asset') ? baseURL + this.config.urls.assets : baseURL + this.config.urls.content_types + this.content_type_uid + this.config.urls.entries;
776+
const baseURL = this.config.protocol + "://" + host + '/' + this.config.version
777+
const url = getRequestUrl(this, baseURL)
778+
779+
755780
this.requestParams = {
756781
method: 'POST',
757782
headers: Utils.mergeDeep({}, this.headers),
@@ -785,7 +810,7 @@ export default class Query extends Entry {
785810
if(this.type && this.type !== 'asset' && this.live_preview && this.live_preview.enable === true && this.live_preview.content_type_uid === this.content_type_uid ) {
786811
host = this.config.protocol + "://" + this.live_preview.host + '/' + this.config.version
787812
}
788-
const url = (this.type && this.type === 'asset') ? host + this.config.urls.assets : host + this.config.urls.content_types + this.content_type_uid + this.config.urls.entries;
813+
const url = getRequestUrl(this, host)
789814

790815
this.singleEntry = true;
791816
this._query.limit = 1;

src/core/stack.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,18 @@ export default class Stack {
351351
return this;
352352
}
353353

354+
/**
355+
* [Taxonomies description]
356+
* @param {[type]} uid [description]
357+
*/
358+
Taxonomies(uid) {
359+
if (uid && typeof uid === 'string') {
360+
this.taxonomy_uid = uid;
361+
this.type = "taxonomy"
362+
}
363+
return this;
364+
}
365+
354366
/**
355367
* @method Entry
356368
* @memberOf ContentType

0 commit comments

Comments
 (0)