Skip to content

Commit 446eb78

Browse files
author
Aamod Pisat
committed
added asset support and minor bug fix
1 parent 1318890 commit 446eb78

File tree

2 files changed

+6
-85
lines changed

2 files changed

+6
-85
lines changed

docs-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"include": [
1010
"src/core/contentstack.js",
1111
"src/core/stack.js",
12-
"src/core/modules/asset.js"
12+
"src/core/modules/asset.js",
1313
"src/core/modules/entry.js",
1414
"src/core/modules/query.js",
1515
"src/core/modules/result.js"

src/core/modules/asset.js

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as Utils from '../lib/utils';
22
import Stack from '../stack';
33
import Query from './query';
4-
<<<<<<< HEAD
5-
=======
64

75
const _extend = function (type) {
86
return function () {
@@ -33,44 +31,11 @@ const _extend = function (type) {
3331
}
3432
};
3533
};
36-
>>>>>>> 5f8e4cdd88f31d7d7d2c98debc826c27c1942e2f
3734
/**
3835
* @summary Creates an instance of `Asset`.
3936
* @description An initializer is responsible for creating Asset object.
4037
* @param {String} uid - uid of the asset
4138
* @example
42-
<<<<<<< HEAD
43-
* let Entry = Contentstack.Stack().Asset('bltsomething123');
44-
* @returns {Asset}
45-
* @ignore
46-
*/
47-
export default class Asset {
48-
constructor(){
49-
this._query = {};
50-
return this;
51-
}
52-
53-
setCacheProvider(provider){
54-
if(provider && typeof provider === 'object') {
55-
this.provider = provider;
56-
57-
}
58-
return this;
59-
}
60-
61-
setCachePolicy(policy){
62-
if(typeof policy === 'number' && policy >= -1 && policy < 4) {
63-
if(!this._query) {
64-
this.cachePolicy = policy;
65-
} else {
66-
this.queryCachePolicy = policy;
67-
}
68-
} else {
69-
console.error("Kindly provide the valid policy");
70-
}
71-
return this;
72-
}
73-
=======
7439
* let Entry = Contentstack.Stack().Assets('bltsomething123');
7540
* @returns {Asset}
7641
* @ignore
@@ -96,34 +61,19 @@ export default class Asset {
9661
this.only = _extend('only');
9762
return this;
9863
}
99-
>>>>>>> 5f8e4cdd88f31d7d7d2c98debc826c27c1942e2f
10064

10165
/**
10266
* @method Query
10367
* @description Query instance to provide support for all search queries.
10468
* @example Assets().Query()
10569
* @returns {Query}
10670
*/
107-
<<<<<<< HEAD
108-
Query(){
109-
=======
11071
Query(){
111-
>>>>>>> 5f8e4cdd88f31d7d7d2c98debc826c27c1942e2f
11272
let query = new Query();
11373
return Utils.merge(query, this);
11474
}
11575

11676
/**
117-
<<<<<<< HEAD
118-
* @method toJSON
119-
* @description This method is used to convert the result in to plain javascript object.
120-
* @example
121-
* blogEntry
122-
* .toJSON()
123-
* .then(function (result) {
124-
* let value = result.get(field_uid)
125-
* },function (error) {
126-
=======
12777
* @method addQuery
12878
* @description This method is used to add query to Entry object.
12979
* @param {String} key - key of the query
@@ -149,50 +99,22 @@ export default class Asset {
14999
* .then(function (result) {
150100
* let value = result.get(field_uid)
151101
* },function (error) {
152-
>>>>>>> 5f8e4cdd88f31d7d7d2c98debc826c27c1942e2f
153102
* // error function
154103
* })
155104
* @returns {Object}
156105
*/
157-
<<<<<<< HEAD
158-
toJSON(){
159-
=======
160106
toJSON(){
161-
>>>>>>> 5f8e4cdd88f31d7d7d2c98debc826c27c1942e2f
162107
this.tojson = true;
163108
return this;
164109
}
165110

166-
<<<<<<< HEAD
167-
=======
168111

169-
>>>>>>> 5f8e4cdd88f31d7d7d2c98debc826c27c1942e2f
170112
/**
171-
* @method fetch
172-
* @description fetch asset obhect of requested Asset uid of defined query if present.
173-
* @example
174-
<<<<<<< HEAD
175-
* Stack.Asset('bltsomething123').fetch()
176-
*/
177-
fetch() {
178-
if (this.asset_uid) {
179-
this.requestParams = {
180-
method: 'POST',
181-
headers: this.headers,
182-
url: this.config.protocol + "://" + this.config.host + ':' + this.config.port + '/' + this.config.version + this.config.urls.assets + this.asset_uid,
183-
body: {
184-
_method: 'GET',
185-
query: this._query
186-
}
187-
}
188-
return Utils.sendRequest(this);
189-
} else {
190-
console.error("Kindly provide an asset uid. e.g. .Asset('bltsomething123')");
191-
}
192-
}
193-
=======
194-
* Stack.Assets('bltsomething123').fetch()
195-
*/
113+
* @method fetch
114+
* @description fetch asset obhect of requested Asset uid of defined query if present.
115+
* @example
116+
* Stack.Assets('bltsomething123').fetch()
117+
*/
196118
fetch() {
197119
if (this.asset_uid) {
198120
this.requestParams = {
@@ -209,5 +131,4 @@ export default class Asset {
209131
console.error("Kindly provide an asset uid. e.g. .Assets('bltsomething123')");
210132
}
211133
}
212-
>>>>>>> 5f8e4cdd88f31d7d7d2c98debc826c27c1942e2f
213134
}

0 commit comments

Comments
 (0)