@veritree/services 0.9.1 → 0.11.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/services/field-updates.js +34 -0
- package/src/services/forest-types.js +7 -2
- package/src/services/form-submissions.js +7 -7
- package/src/services/images.js +13 -2
- package/src/services/regions.js +34 -10
- package/src/services/subsites.js +28 -8
- package/utils/args.js +33 -0
package/package.json
CHANGED
|
@@ -5,6 +5,10 @@ export const createFieldUpdatesApiService = () => {
|
|
|
5
5
|
const resource = `field-updates`;
|
|
6
6
|
const { orgId, orgType } = getSession();
|
|
7
7
|
|
|
8
|
+
if (!orgId && !orgType) {
|
|
9
|
+
throw new Error('Organization id and type are required');
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
const get = {
|
|
9
13
|
async all(countryId, regionId, subsiteId, page = 1, orderBy = 'date_planted-desc', pageSize = 10) {
|
|
10
14
|
const params = `${_getParams(
|
|
@@ -19,6 +23,23 @@ export const createFieldUpdatesApiService = () => {
|
|
|
19
23
|
|
|
20
24
|
return await Api.get(url);
|
|
21
25
|
},
|
|
26
|
+
|
|
27
|
+
async specific(id) {
|
|
28
|
+
const url = `${_getUrl()}/${id}?${_getParams()}`;
|
|
29
|
+
|
|
30
|
+
return await Api.get(url);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param {object} data
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
const post = (data) => {
|
|
40
|
+
const url = `${_getUrl()}?${_getParams()}`;
|
|
41
|
+
|
|
42
|
+
return Api.post(url, data);
|
|
22
43
|
};
|
|
23
44
|
|
|
24
45
|
/**
|
|
@@ -33,6 +54,17 @@ export const createFieldUpdatesApiService = () => {
|
|
|
33
54
|
return Api.post(url, data);
|
|
34
55
|
};
|
|
35
56
|
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
const remove = {
|
|
61
|
+
async img(fieldUpdateId, data) {
|
|
62
|
+
const url = `${_getUrl()}/${fieldUpdateId}/images/detach?${_getParams()}`;
|
|
63
|
+
|
|
64
|
+
return await Api.post(url, data);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
36
68
|
const _getUrl = () => {
|
|
37
69
|
return `${Api.baseUrl}/${resource}`;
|
|
38
70
|
};
|
|
@@ -51,6 +83,8 @@ export const createFieldUpdatesApiService = () => {
|
|
|
51
83
|
|
|
52
84
|
return {
|
|
53
85
|
get,
|
|
86
|
+
post,
|
|
54
87
|
update,
|
|
88
|
+
remove
|
|
55
89
|
};
|
|
56
90
|
};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import Api from '../helpers/api';
|
|
2
|
+
import { getSession } from "../helpers/session";
|
|
2
3
|
|
|
3
|
-
export const createForestTypesApiService = (
|
|
4
|
-
if (!orgId || !orgType) throw new Error('orgId and orgType are required');
|
|
4
|
+
export const createForestTypesApiService = () => {
|
|
5
5
|
const resource = 'forest-types';
|
|
6
|
+
const { orgId, orgType } = getSession();
|
|
7
|
+
|
|
8
|
+
if (!orgId && !orgType) {
|
|
9
|
+
throw new Error('Organization id and type are required');
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
const get = {
|
|
8
13
|
/**
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import Api from '../helpers/api';
|
|
2
|
+
import { getSession } from "../helpers/session";
|
|
2
3
|
|
|
3
|
-
export const createFormSubmissionsApiService = (
|
|
4
|
-
if (!orgId) throw new Error('orgId and orgType are required');
|
|
4
|
+
export const createFormSubmissionsApiService = () => {
|
|
5
5
|
const resource = 'form-submissions';
|
|
6
|
+
const { orgId, orgType } = getSession();
|
|
7
|
+
|
|
8
|
+
if (!orgId && !orgType) {
|
|
9
|
+
throw new Error('Organization id and type are required');
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
const get = {
|
|
8
13
|
async all(page = 1, pageSize = 10) {
|
|
9
14
|
const url = `${_getUrl()}?${_getParams(page, pageSize)}`;
|
|
10
15
|
return await Api.get(url);
|
|
11
16
|
},
|
|
12
|
-
|
|
13
|
-
// async specific(formId) {
|
|
14
|
-
// const url = `${_getUrl()}/${orgId}/forms/${formId}?${_getParams()}`;
|
|
15
|
-
// return await Api.get(url);
|
|
16
|
-
// },
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const _getUrl = () => {
|
package/src/services/images.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import Api from "../helpers/api";
|
|
2
|
+
import { getSession } from "../helpers/session";
|
|
2
3
|
|
|
3
|
-
export const createImagesApiService = (
|
|
4
|
-
if (!orgId && !orgType) throw new Error("orgId and orgType are required");
|
|
4
|
+
export const createImagesApiService = () => {
|
|
5
5
|
const resource = "images";
|
|
6
|
+
const { orgId, orgType } = getSession();
|
|
7
|
+
|
|
8
|
+
if (!orgId && !orgType) {
|
|
9
|
+
throw new Error('Organization id and type are required');
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
const get = {
|
|
8
13
|
async all(
|
|
@@ -23,6 +28,12 @@ export const createImagesApiService = (orgId, orgType) => {
|
|
|
23
28
|
)}`;
|
|
24
29
|
return await Api.get(url);
|
|
25
30
|
},
|
|
31
|
+
|
|
32
|
+
async specific(id) {
|
|
33
|
+
const url = `${_getUrl()}/${id}?${_getParams()}`;
|
|
34
|
+
|
|
35
|
+
return await Api.get(url);
|
|
36
|
+
}
|
|
26
37
|
};
|
|
27
38
|
|
|
28
39
|
const _getUrl = () => {
|
package/src/services/regions.js
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
|
-
import Api from
|
|
1
|
+
import Api from "../helpers/api";
|
|
2
|
+
import { getSession } from "../helpers/session";
|
|
2
3
|
|
|
3
|
-
export const createRegionsApiService = (
|
|
4
|
-
|
|
5
|
-
const
|
|
4
|
+
export const createRegionsApiService = () => {
|
|
5
|
+
const resource = "regions";
|
|
6
|
+
const { orgId, orgType } = getSession();
|
|
7
|
+
|
|
8
|
+
if (!orgId && !orgType) {
|
|
9
|
+
throw new Error("Organization id and type are required");
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
const get = {
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Gets all regions of an organization
|
|
15
|
+
*
|
|
16
|
+
* @param {obj} pagination { page, pageSize }
|
|
17
|
+
* @param {obj} filters { countryId, regionId }
|
|
18
|
+
* @returns {obj} envelope
|
|
19
|
+
*/
|
|
20
|
+
async all(
|
|
21
|
+
pagination = { page: 1, pageSize: 10},
|
|
22
|
+
filters = { countryId: null },
|
|
23
|
+
advancedQuery = { includes: [], excludes: [] },
|
|
24
|
+
) {
|
|
25
|
+
let { page, pageSize } = pagination;
|
|
26
|
+
const { countryId } = filters;
|
|
27
|
+
const { includes, excludes } = advancedQuery;
|
|
28
|
+
|
|
29
|
+
const url = `${_getUrl()}?${_getParams(countryId, page, pageSize, includes, excludes)}`;
|
|
10
30
|
return await Api.get(url);
|
|
11
31
|
},
|
|
12
32
|
};
|
|
@@ -15,11 +35,15 @@ export const createRegionsApiService = (orgId, orgType) => {
|
|
|
15
35
|
return `${Api.baseUrl}/${resource}`;
|
|
16
36
|
};
|
|
17
37
|
|
|
18
|
-
const _getParams = (page, pageSize) => {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
38
|
+
const _getParams = (countryId, page, pageSize, includes, excludes) => {
|
|
39
|
+
const countryIdParam = countryId ? `&country_id=${countryId}` : "";
|
|
40
|
+
const pageParam = page ? `&page=${page}` : "";
|
|
41
|
+
const pageSizeParam = pageSize ? `&page_size=${pageSize}` : "";
|
|
42
|
+
const includeParams = includes ? includes.map(item => `&include[]=${item}`).join('') : "";
|
|
43
|
+
const excludeParams = excludes ? excludes.map(item => `&exclude=${item}`).join('') : "";
|
|
44
|
+
const params = `${countryIdParam}${pageParam}${pageSizeParam}${includeParams}${excludeParams}`;
|
|
21
45
|
|
|
22
|
-
return `org_id=${orgId}&org_type=${orgType}${
|
|
46
|
+
return `org_id=${orgId}&org_type=${orgType}${params}`;
|
|
23
47
|
};
|
|
24
48
|
|
|
25
49
|
return {
|
package/src/services/subsites.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import Api from '../helpers/api';
|
|
2
|
+
import { getSession } from "../helpers/session";
|
|
2
3
|
|
|
3
|
-
export const createSubsitesApiService = (
|
|
4
|
-
if (!orgId && !orgType) throw new Error('orgId is required');
|
|
4
|
+
export const createSubsitesApiService = () => {
|
|
5
5
|
const resource = 'subsites';
|
|
6
|
+
const { orgId, orgType } = getSession();
|
|
7
|
+
|
|
8
|
+
if (!orgId && !orgType) {
|
|
9
|
+
throw new Error('Organization id and type are required');
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
const get = {
|
|
8
13
|
/**
|
|
9
14
|
* Gets all subsites of an organization
|
|
10
15
|
*
|
|
11
|
-
* @param {
|
|
12
|
-
* @
|
|
16
|
+
* @param {obj} pagination { page, pageSize }
|
|
17
|
+
* @param {obj} filters { countryId, regionId }
|
|
18
|
+
* @returns {obj} envelope
|
|
13
19
|
*/
|
|
14
|
-
async all(
|
|
15
|
-
|
|
20
|
+
async all(
|
|
21
|
+
pagination = { page: 1, pageSize: 10},
|
|
22
|
+
filters = { countryId: null, regionId: null }
|
|
23
|
+
) {
|
|
24
|
+
let { page, pageSize } = pagination;
|
|
25
|
+
const { countryId, regionId } = filters;
|
|
26
|
+
|
|
27
|
+
const url = `${_getUrl()}?${_getUrlParams(countryId, regionId, page, pageSize)}`;
|
|
28
|
+
|
|
16
29
|
return await Api.get(url);
|
|
17
30
|
},
|
|
18
31
|
|
|
@@ -25,6 +38,7 @@ export const createSubsitesApiService = (orgId, orgType) => {
|
|
|
25
38
|
*/
|
|
26
39
|
async specific(id, page = 1, pageSize = 10) {
|
|
27
40
|
const url = `${_getUrl()}/${id}?${_getUrlParams(page, pageSize)}`;
|
|
41
|
+
|
|
28
42
|
return await Api.get(url);
|
|
29
43
|
},
|
|
30
44
|
};
|
|
@@ -33,8 +47,14 @@ export const createSubsitesApiService = (orgId, orgType) => {
|
|
|
33
47
|
return `${Api.baseUrl}/${resource}`;
|
|
34
48
|
};
|
|
35
49
|
|
|
36
|
-
const _getUrlParams = (page, pageSize) => {
|
|
37
|
-
|
|
50
|
+
const _getUrlParams = (countryId, regionId, page, pageSize) => {
|
|
51
|
+
const countryIdParam = countryId ? `&country_id=${countryId}` : "";
|
|
52
|
+
const regionIdParam = regionId ? `®ion_id=${regionId}` : "";
|
|
53
|
+
const pageParam = page ? `&page=${page}` : "";
|
|
54
|
+
const pageSizeParam = pageSize ? `&page_size=${pageSize}` : "";
|
|
55
|
+
const params = `${countryIdParam}${regionIdParam}${pageParam}${pageSizeParam}`;
|
|
56
|
+
|
|
57
|
+
return `org_id=${orgId}&org_type=${orgType}${params}`;
|
|
38
58
|
};
|
|
39
59
|
|
|
40
60
|
return {
|
package/utils/args.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function getArgs() {
|
|
2
|
+
const argsString = [];
|
|
3
|
+
let arr = [];
|
|
4
|
+
|
|
5
|
+
for(arg of arguments) {
|
|
6
|
+
if(typeof arg === 'object') {
|
|
7
|
+
for(key in arg) {
|
|
8
|
+
if(arg[key] === null) return;
|
|
9
|
+
|
|
10
|
+
if(Array.isArray(arg[key])) {
|
|
11
|
+
arr = arg[key].map((item, index) => {
|
|
12
|
+
const param = `${key}[]=${item}`;
|
|
13
|
+
|
|
14
|
+
return index === 0 ? `${param}` : `&${param}`;
|
|
15
|
+
}).join('');
|
|
16
|
+
|
|
17
|
+
argsString.push(arr);
|
|
18
|
+
} else {
|
|
19
|
+
argsString.push(`${key}=${arg[key]}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
console.log(argsString.join('&'));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const pagination = { page: 1, pageSize: 3}
|
|
29
|
+
const filter = { countryId: 4, regionId: 5}
|
|
30
|
+
const sort = { orderBy: 'date_planted-desc'}
|
|
31
|
+
const advancedQuery = { include: ['a', 'b'], exclude: ['country']}
|
|
32
|
+
|
|
33
|
+
getArgs(pagination, filter, sort, advancedQuery);
|