@veritree/services 0.6.1 → 0.7.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": "0.6.1",
3
+ "version": "0.7.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,38 +1,38 @@
1
1
  import Api from '../helpers/api';
2
2
 
3
- // TODO: Add all possible parameters as in API
4
- export const createForestTypesApiService = () => {
3
+ export const createForestTypesApiService = (orgId, orgType) => {
4
+ if (!orgId || !orgType) throw new Error('orgId and orgType are required');
5
+ const resource = 'forest-types';
6
+
5
7
  const get = {
6
8
  /**
7
- * Gets all forest types of an organization
8
- *
9
- * @param {boolean} isPublic
10
9
  * @returns {object} envelope
11
10
  */
12
- async all(isPublic = false) {
13
- const url = `${_getUrl(isPublic)}`;
11
+ async all(page = 1, pageSize = 10) {
12
+ const url = `${_getUrl()}?${_getParams(page, pageSize)}`;
14
13
  return await Api.get(url);
15
14
  },
16
15
 
17
16
  /**
18
- * Gets a speficific forest type of an organization
19
- *
20
17
  * @param {number/string} id
21
- * @param {boolean} isPublic
22
18
  * @returns {object} envelope
23
19
  */
24
- async specific(id, isPublic = false) {
25
- const url = `${_getUrl(isPublic)}/${id}`;
20
+ async specific(id) {
21
+ const url = `${_getUrl()}/${id}?${_getParams(page, pageSize)}`;
26
22
  return await Api.get(url);
27
23
  },
28
24
  };
29
25
 
30
- const _getResource = (isPublic) => {
31
- return isPublic ? 'forest-type-profiles' : `forest-types`;
26
+ const _getUrl = () => {
27
+ return `${Api.baseUrl}/${resource}`;
32
28
  };
33
29
 
34
- const _getUrl = (isPublic) => {
35
- return `${Api.baseUrl}/${_getResource(isPublic)}`
30
+ const _getParams = (page, pageSize) => {
31
+ const pageParam = page ? `&page=${page}` : '';
32
+ const pageSizeParam = pageSize ? `&page_size=${pageSize}` : '';
33
+ const params = `${pageParam}${pageSizeParam}`;
34
+
35
+ return `org_id=${orgId}&org_type=${orgType}${params}`;
36
36
  };
37
37
 
38
38
  return {