@veritree/services 2.66.0 → 2.68.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/planting-sites.js +32 -0
- package/src/utils/args.js +13 -5
package/package.json
CHANGED
|
@@ -6,6 +6,25 @@ class PlantingSitesApi extends Api {
|
|
|
6
6
|
this.resource = 'planting-sites';
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
public() {
|
|
10
|
+
const all = async (params) => {
|
|
11
|
+
const url = `${this.getUrl()}/public${this.getUrlParams(
|
|
12
|
+
params
|
|
13
|
+
)}`;
|
|
14
|
+
return await this.get(url);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const single = async (plantingSiteId) => {
|
|
18
|
+
const url = `${this.getUrl()}/public/${plantingSiteId}`;
|
|
19
|
+
return await this.get(url);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
all,
|
|
24
|
+
single,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
9
28
|
users(plantingSiteId) {
|
|
10
29
|
let url = `${this.getUrl()}/${plantingSiteId}/users`;
|
|
11
30
|
|
|
@@ -129,6 +148,19 @@ class PlantingSitesApi extends Api {
|
|
|
129
148
|
all,
|
|
130
149
|
};
|
|
131
150
|
}
|
|
151
|
+
|
|
152
|
+
locations() {
|
|
153
|
+
const all = async (params) => {
|
|
154
|
+
const url = `${this.getUrl()}/locations-by-org${this.getUrlParams(
|
|
155
|
+
params
|
|
156
|
+
)}`;
|
|
157
|
+
return await this.get(url);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
all
|
|
162
|
+
}
|
|
163
|
+
}
|
|
132
164
|
}
|
|
133
165
|
|
|
134
166
|
export const PlantingSites = new PlantingSitesApi();
|
package/src/utils/args.js
CHANGED
|
@@ -11,12 +11,18 @@ export const createParamsStringFromArgs = (args) => {
|
|
|
11
11
|
|
|
12
12
|
if (Array.isArray(value)) {
|
|
13
13
|
arr = value
|
|
14
|
+
.filter((item) => item !== undefined && item !== null && item !== "")
|
|
14
15
|
.map((item, index) => {
|
|
15
16
|
const param = `${key}[]=${encodeURIComponent(item)}`;
|
|
17
|
+
|
|
16
18
|
return index === 0 ? `${param}` : `&${param}`;
|
|
17
19
|
})
|
|
18
20
|
.join("");
|
|
19
21
|
|
|
22
|
+
if (!arr.length) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
paramsString.push(arr);
|
|
21
27
|
} else {
|
|
22
28
|
if (value !== undefined) {
|
|
@@ -27,17 +33,19 @@ export const createParamsStringFromArgs = (args) => {
|
|
|
27
33
|
* solution, we have this -x- to allow
|
|
28
34
|
* same keys to be passed. The args
|
|
29
35
|
* would look like:
|
|
30
|
-
*
|
|
31
|
-
* {
|
|
36
|
+
*
|
|
37
|
+
* {
|
|
32
38
|
* 'box-x-1': 1
|
|
33
39
|
* 'box-x-2': 2
|
|
34
40
|
* }
|
|
35
|
-
*
|
|
41
|
+
*
|
|
36
42
|
* and would be translated as expected:
|
|
37
|
-
*
|
|
43
|
+
*
|
|
38
44
|
* box=1&box=2
|
|
39
45
|
*/
|
|
40
|
-
paramsString.push(
|
|
46
|
+
paramsString.push(
|
|
47
|
+
`${key.split("-x-")[0]}=${encodeURIComponent(value)}`
|
|
48
|
+
);
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
});
|