@veritree/services 2.59.0 → 2.60.0
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/endpoints/organizations.js +15 -3
- package/src/endpoints/tree-codes.js +54 -2
- package/src/helpers/api.js +13 -3
package/package.json
CHANGED
|
@@ -71,9 +71,7 @@ class OrganizationsApi extends Api {
|
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
const create = async (data, params) => {
|
|
74
|
-
const url = `${this.getUrl()}/${orgId}/pins${this.getUrlParams(
|
|
75
|
-
params
|
|
76
|
-
)}`;
|
|
74
|
+
const url = `${this.getUrl()}/${orgId}/pins${this.getUrlParams(params)}`;
|
|
77
75
|
|
|
78
76
|
return await this.post(url, data);
|
|
79
77
|
};
|
|
@@ -95,6 +93,20 @@ class OrganizationsApi extends Api {
|
|
|
95
93
|
all,
|
|
96
94
|
};
|
|
97
95
|
}
|
|
96
|
+
|
|
97
|
+
plantingReport(orgId) {
|
|
98
|
+
const all = async (params) => {
|
|
99
|
+
const url = `${this.getUrl()}/${orgId}/planting-report${this.getUrlParams(
|
|
100
|
+
params
|
|
101
|
+
)}`;
|
|
102
|
+
|
|
103
|
+
return await this.get(url);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
all,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
export const Organizations = new OrganizationsApi();
|
|
@@ -54,8 +54,8 @@ class TreeCodesApi extends Api {
|
|
|
54
54
|
return await this.post(url, data);
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
const single = async (id) => {
|
|
58
|
-
const url = `${this.getUrl()}/campaigns/${id}`;
|
|
57
|
+
const single = async (id, params) => {
|
|
58
|
+
const url = `${this.getUrl()}/campaigns/${id}${this.getUrlParams(params)}`;
|
|
59
59
|
|
|
60
60
|
return await this.get(url);
|
|
61
61
|
};
|
|
@@ -111,6 +111,58 @@ class TreeCodesApi extends Api {
|
|
|
111
111
|
all,
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
batches() {
|
|
116
|
+
/**
|
|
117
|
+
* Fetches batches data
|
|
118
|
+
* @param {string} orgType - The shortened identifier for the organization type (o, s, r).
|
|
119
|
+
* @param {string} orgPublicId - The public identifier of the organization.
|
|
120
|
+
* @param {Object} params - Additional parameters for the API request.
|
|
121
|
+
* @returns {Object} An object with a method 'all' to initiate the API request and retrieve recipes based on the provided parameters.
|
|
122
|
+
*/
|
|
123
|
+
const all = async (orgType, orgPublicId, params) => {
|
|
124
|
+
const url = this._constructFetchUrl(
|
|
125
|
+
orgType,
|
|
126
|
+
orgPublicId,
|
|
127
|
+
"batches",
|
|
128
|
+
params
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
return await this.get(url);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const download = async (batchPublicId, params) => {
|
|
135
|
+
return await this.get(`${this.getUrl()}/batches/download/${batchPublicId}${this.getUrlParams(params)}`)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
all,
|
|
140
|
+
download
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
batchByCampaingAndRecipe() {
|
|
145
|
+
/**
|
|
146
|
+
* @param {string} orgType - The shortened identifier for the organization type (o, s, r).
|
|
147
|
+
* @param {string} orgPublicId - The public identifier of the organization.
|
|
148
|
+
* @param {Object} params - Additional parameters for the API request.
|
|
149
|
+
* @returns {Object} An object with a method 'all' to initiate the API request and retrieve recipes based on the provided parameters.
|
|
150
|
+
*/
|
|
151
|
+
const post = async (orgType, orgPublicId, params, data) => {
|
|
152
|
+
const url = this._constructFetchUrl(
|
|
153
|
+
orgType,
|
|
154
|
+
orgPublicId,
|
|
155
|
+
"batch-by-campaign-and-recipe",
|
|
156
|
+
params
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
return await this.post(url, data);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
post
|
|
164
|
+
}
|
|
165
|
+
}
|
|
114
166
|
}
|
|
115
167
|
|
|
116
168
|
export const TreeCodes = new TreeCodesApi();
|
package/src/helpers/api.js
CHANGED
|
@@ -277,9 +277,19 @@ export default class Api {
|
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
response.
|
|
281
|
-
|
|
282
|
-
|
|
280
|
+
const headerContentType = response.headers.get('content-type');
|
|
281
|
+
|
|
282
|
+
if (headerContentType.includes('json')) {
|
|
283
|
+
response.json().then((json) => {
|
|
284
|
+
response.ok ? resolve(json) : reject(json);
|
|
285
|
+
});
|
|
286
|
+
} else if (headerContentType.includes('csv')) {
|
|
287
|
+
response.text().then((res) => {
|
|
288
|
+
response.ok ? resolve(res) : reject(res);
|
|
289
|
+
});
|
|
290
|
+
} else {
|
|
291
|
+
throw new Error("This response header content-type is not handled.");
|
|
292
|
+
}
|
|
283
293
|
});
|
|
284
294
|
}
|
|
285
295
|
|