@veritree/services 2.27.2 → 2.29.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.27.2",
3
+ "version": "2.29.0",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,9 +1,9 @@
1
- import Api from "../helpers/api";
1
+ import Api from '../helpers/api';
2
2
 
3
3
  class OrganizationsApi extends Api {
4
4
  constructor(resource) {
5
5
  super(resource);
6
- this.resource = "organizations";
6
+ this.resource = 'organizations';
7
7
  }
8
8
 
9
9
  tasks(orgId) {
@@ -41,7 +41,18 @@ class OrganizationsApi extends Api {
41
41
  return {
42
42
  all,
43
43
  create,
44
- }
44
+ };
45
+ }
46
+
47
+ plantingStats(orgId) {
48
+ const all = async (params) => {
49
+ const url = `${this.getUrl()}/${orgId}/field-updates/planting-stats${this.getUrlParams(
50
+ params
51
+ )}`;
52
+ return await this.get(url);
53
+ };
54
+
55
+ return { all };
45
56
  }
46
57
  }
47
58
 
@@ -217,29 +217,33 @@ export default class Api {
217
217
  getUrlParams(args) {
218
218
  this.setOrg();
219
219
  let isOrgLess = false;
220
- let isOrgAs = false;
220
+ let isOrgIdAs = false;
221
+ let isOrgTypeAs = false;
221
222
  let orgIdParam = "";
222
223
  let orgTypeParam = "";
224
+ let argsClone = structuredClone(args); // avoids mutating object
223
225
 
224
226
  // while most of endpoints require an org id and type, some endpoints do not
225
- if (args) {
226
- isOrgLess = Object.hasOwn(args, "orgless");
227
- isOrgAs =
228
- Object.hasOwn(args, "org_id_as") && Object.hasOwn(args, "org_type_as");
227
+ if (argsClone) {
228
+ isOrgLess = Object.hasOwn(argsClone, "orgless");
229
+ isOrgIdAs = Object.hasOwn(argsClone, "org_id_as");
230
+ isOrgTypeAs = Object.hasOwn(argsClone, "org_type_as");
229
231
  }
230
232
 
231
233
  // a super admin user can create/edit data from other orgs
232
234
  // and for that, we can't use the org id and type in
233
235
  // the session.
234
- if (isOrgAs) {
235
- orgIdParam = `org_id=${args.org_id_as}`;
236
- orgTypeParam = `&org_type=${args.org_type_as}`;
236
+ if (isOrgIdAs) {
237
+ this.orgId = `org_id=${argsClone.org_id_as}`;
238
+ delete argsClone.org_id_as;
239
+ }
237
240
 
238
- delete args.org_id_as;
239
- delete args.org_type_as;
241
+ if (isOrgTypeAs) {
242
+ this.orgType = `&org_type=${argsClone.org_type_as}`;
243
+ delete argsClone.org_type_as;
240
244
  }
241
245
 
242
- if (!isOrgLess && !isOrgAs) {
246
+ if (!isOrgLess) {
243
247
  if (this.orgId) {
244
248
  orgIdParam = `org_id=${this.orgId}`;
245
249
  }
@@ -247,13 +251,11 @@ export default class Api {
247
251
  if (this.orgType) {
248
252
  orgTypeParam = `&org_type=${this.orgType}`;
249
253
  }
250
-
251
- if (args && args.orgType) {
252
- orgTypeParam = `&org_type=${args.orgType}`;
253
- }
254
254
  }
255
255
 
256
- return `?${orgIdParam}${orgTypeParam}${createParamsStringFromArgs(args)}`;
256
+ return `?${orgIdParam}${orgTypeParam}${createParamsStringFromArgs(
257
+ argsClone
258
+ )}`;
257
259
  }
258
260
 
259
261
  /**