@veritree/services 0.11.0 → 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/form-submissions.js +7 -7
- package/src/services/regions.js +28 -9
- package/src/services/subsites.js +21 -6
- package/utils/args.js +33 -0
package/package.json
CHANGED
|
@@ -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/regions.js
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import Api from
|
|
1
|
+
import Api from "../helpers/api";
|
|
2
2
|
import { getSession } from "../helpers/session";
|
|
3
3
|
|
|
4
4
|
export const createRegionsApiService = () => {
|
|
5
|
-
const resource =
|
|
5
|
+
const resource = "regions";
|
|
6
6
|
const { orgId, orgType } = getSession();
|
|
7
7
|
|
|
8
8
|
if (!orgId && !orgType) {
|
|
9
|
-
throw new Error(
|
|
9
|
+
throw new Error("Organization id and type are required");
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const get = {
|
|
13
|
-
|
|
14
|
-
|
|
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)}`;
|
|
15
30
|
return await Api.get(url);
|
|
16
31
|
},
|
|
17
32
|
};
|
|
@@ -20,11 +35,15 @@ export const createRegionsApiService = () => {
|
|
|
20
35
|
return `${Api.baseUrl}/${resource}`;
|
|
21
36
|
};
|
|
22
37
|
|
|
23
|
-
const _getParams = (page, pageSize) => {
|
|
24
|
-
const
|
|
25
|
-
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}`;
|
|
26
45
|
|
|
27
|
-
return `org_id=${orgId}&org_type=${orgType}${
|
|
46
|
+
return `org_id=${orgId}&org_type=${orgType}${params}`;
|
|
28
47
|
};
|
|
29
48
|
|
|
30
49
|
return {
|
package/src/services/subsites.js
CHANGED
|
@@ -13,11 +13,19 @@ export const createSubsitesApiService = () => {
|
|
|
13
13
|
/**
|
|
14
14
|
* Gets all subsites of an organization
|
|
15
15
|
*
|
|
16
|
-
* @param {
|
|
17
|
-
* @
|
|
16
|
+
* @param {obj} pagination { page, pageSize }
|
|
17
|
+
* @param {obj} filters { countryId, regionId }
|
|
18
|
+
* @returns {obj} envelope
|
|
18
19
|
*/
|
|
19
|
-
async all(
|
|
20
|
-
|
|
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
|
+
|
|
21
29
|
return await Api.get(url);
|
|
22
30
|
},
|
|
23
31
|
|
|
@@ -30,6 +38,7 @@ export const createSubsitesApiService = () => {
|
|
|
30
38
|
*/
|
|
31
39
|
async specific(id, page = 1, pageSize = 10) {
|
|
32
40
|
const url = `${_getUrl()}/${id}?${_getUrlParams(page, pageSize)}`;
|
|
41
|
+
|
|
33
42
|
return await Api.get(url);
|
|
34
43
|
},
|
|
35
44
|
};
|
|
@@ -38,8 +47,14 @@ export const createSubsitesApiService = () => {
|
|
|
38
47
|
return `${Api.baseUrl}/${resource}`;
|
|
39
48
|
};
|
|
40
49
|
|
|
41
|
-
const _getUrlParams = (page, pageSize) => {
|
|
42
|
-
|
|
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}`;
|
|
43
58
|
};
|
|
44
59
|
|
|
45
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);
|