@veritree/services 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/helpers/api.js +17 -10
- package/src/services/field-updates.js +2 -2
package/package.json
CHANGED
package/src/helpers/api.js
CHANGED
|
@@ -8,12 +8,12 @@ const Api = {
|
|
|
8
8
|
return await this.unWrap(url);
|
|
9
9
|
},
|
|
10
10
|
|
|
11
|
-
async post(url, data) {
|
|
12
|
-
return await this.unWrap(url, 'post', data);
|
|
11
|
+
async post(url, data, isMultipart = false) {
|
|
12
|
+
return await this.unWrap(url, 'post', data, isMultipart);
|
|
13
13
|
},
|
|
14
14
|
|
|
15
|
-
async update(url, data) {
|
|
16
|
-
return await this.unWrap(url, 'put', data);
|
|
15
|
+
async update(url, data, isMultipart = false) {
|
|
16
|
+
return await this.unWrap(url, 'put', data, isMultipart);
|
|
17
17
|
},
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -24,9 +24,9 @@ const Api = {
|
|
|
24
24
|
* @param {object} data
|
|
25
25
|
* @returns {object} envelope
|
|
26
26
|
*/
|
|
27
|
-
async unWrap(url, method = 'get', data) {
|
|
27
|
+
async unWrap(url, method = 'get', data, isMultipart) {
|
|
28
28
|
if (this.forceEnvelopeResponse) url = this.addEvenlopeArgToUrl(url); // TODO: remove when API is fully migrated to envelopes
|
|
29
|
-
const config = this.getConfig(method, data);
|
|
29
|
+
const config = this.getConfig(method, data, isMultipart);
|
|
30
30
|
|
|
31
31
|
try {
|
|
32
32
|
const response = await fetch(url, config);
|
|
@@ -45,16 +45,23 @@ const Api = {
|
|
|
45
45
|
* @param {object} body
|
|
46
46
|
* @returns {object} data
|
|
47
47
|
*/
|
|
48
|
-
getConfig(method, data) {
|
|
48
|
+
getConfig(method, data, isMultipart) {
|
|
49
|
+
const contentType = isMultipart ? 'multipart/form-data' : 'application/json';
|
|
50
|
+
const token = `Bearer ${getCookie('access_token')}`;
|
|
51
|
+
|
|
49
52
|
const config = {
|
|
50
53
|
method,
|
|
51
54
|
headers: {
|
|
52
|
-
'Content-Type':
|
|
53
|
-
Authorization:
|
|
55
|
+
'Content-Type': contentType,
|
|
56
|
+
Authorization: token
|
|
54
57
|
},
|
|
55
58
|
};
|
|
56
59
|
|
|
57
|
-
if (method !== 'get'
|
|
60
|
+
if (method !== 'get' && !isMultipart) {
|
|
61
|
+
config.body = JSON.stringify(data);
|
|
62
|
+
} else {
|
|
63
|
+
config.body = data;
|
|
64
|
+
}
|
|
58
65
|
|
|
59
66
|
return config;
|
|
60
67
|
},
|
|
@@ -24,10 +24,10 @@ export const createFieldUpdatesApiService = (orgId, orgType) => {
|
|
|
24
24
|
* @param {object} data
|
|
25
25
|
* @returns
|
|
26
26
|
*/
|
|
27
|
-
const update = (fieldUpdateId, data) => {
|
|
27
|
+
const update = (fieldUpdateId, data, isMultipart = false) => {
|
|
28
28
|
const url = `${_getUrl()}/${fieldUpdateId}?${_getParams()}`;
|
|
29
29
|
|
|
30
|
-
return Api.update(url, data);
|
|
30
|
+
return Api.update(url, data, isMultipart);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const _getUrl = () => {
|