@veritree/services 0.17.1 → 1.0.0-10
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/index.js +38 -28
- package/package.json +1 -1
- package/src/endpoints/countries.js +5 -0
- package/src/endpoints/field-udpate-verifications.js +5 -0
- package/src/endpoints/field-updates.js +5 -0
- package/src/endpoints/forest-type-species.js +5 -0
- package/src/endpoints/forest-types-profiles.js +5 -0
- package/src/endpoints/forest-types.js +5 -0
- package/src/endpoints/form-submissions.js +5 -0
- package/src/endpoints/images.js +5 -0
- package/src/endpoints/notes.js +15 -0
- package/src/endpoints/orgs.js +25 -0
- package/src/endpoints/regions.js +5 -0
- package/src/endpoints/sdgs.js +5 -0
- package/src/endpoints/sponsors.js +34 -0
- package/src/endpoints/stats.js +17 -0
- package/src/endpoints/subdomains.js +5 -0
- package/src/endpoints/subsite-types.js +5 -0
- package/src/endpoints/subsites.js +5 -0
- package/src/endpoints/trees-orders.js +6 -0
- package/src/endpoints/user.js +15 -0
- package/src/helpers/api.js +171 -79
- package/src/helpers/session.js +0 -4
- package/src/utils/args.js +17 -22
- package/package-lock.json +0 -13
- package/src/services/countries.js +0 -35
- package/src/services/field-udpate-verifications.js +0 -34
- package/src/services/field-updates.js +0 -77
- package/src/services/forest-types.js +0 -48
- package/src/services/form-submissions.js +0 -33
- package/src/services/forms.js +0 -33
- package/src/services/images.js +0 -39
- package/src/services/me.js +0 -20
- package/src/services/orgs.js +0 -31
- package/src/services/regions.js +0 -41
- package/src/services/sponsors.js +0 -31
- package/src/services/subdomains.js +0 -26
- package/src/services/subsite-types.js +0 -70
- package/src/services/subsites.js +0 -70
- package/src/services/trees-orders.js +0 -42
package/index.js
CHANGED
|
@@ -1,31 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
1
|
+
import { Countries } from './src/endpoints/countries';
|
|
2
|
+
import { FieldUpdates } from './src/endpoints/field-updates';
|
|
3
|
+
import { FieldUpdateVerifications } from './src/endpoints/field-udpate-verifications';
|
|
4
|
+
import { FormSubmissions } from './src/endpoints/form-submissions';
|
|
5
|
+
import { ForestTypeSpecies } from './src/endpoints/forest-type-species';
|
|
6
|
+
import { ForestTypes } from './src/endpoints/forest-types';
|
|
7
|
+
import { ForestTypeProfiles } from './src/endpoints/forest-types-profiles';
|
|
8
|
+
import { Images } from './src/endpoints/images';
|
|
9
|
+
import { Orgs } from './src/endpoints/orgs';
|
|
10
|
+
import { Notes } from './src/endpoints/notes';
|
|
11
|
+
import { Regions } from './src/endpoints/regions';
|
|
12
|
+
import { SDGs } from './src/endpoints/sdgs';
|
|
13
|
+
import { Sponsors } from './src/endpoints/sponsors';
|
|
14
|
+
import { Stats } from './src/endpoints/stats';
|
|
15
|
+
import { Subdomains } from './src/endpoints/subdomains';
|
|
16
|
+
import { Subsites } from './src/endpoints/subsites';
|
|
17
|
+
import { SubsiteTypes } from './src/endpoints/subsite-types';
|
|
18
|
+
import { TreeOrders } from './src/endpoints/trees-orders';
|
|
19
|
+
import { User } from './src/endpoints/user';
|
|
15
20
|
|
|
16
21
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
Countries,
|
|
23
|
+
FieldUpdates,
|
|
24
|
+
FieldUpdateVerifications,
|
|
25
|
+
ForestTypeSpecies,
|
|
26
|
+
ForestTypes,
|
|
27
|
+
ForestTypeProfiles,
|
|
28
|
+
FormSubmissions,
|
|
29
|
+
Images,
|
|
30
|
+
Orgs,
|
|
31
|
+
Notes,
|
|
32
|
+
Regions,
|
|
33
|
+
SDGs,
|
|
34
|
+
Sponsors,
|
|
35
|
+
Stats,
|
|
36
|
+
Subdomains,
|
|
37
|
+
Subsites,
|
|
38
|
+
SubsiteTypes,
|
|
39
|
+
TreeOrders,
|
|
40
|
+
User
|
|
31
41
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Api from "../helpers/api";
|
|
2
|
+
|
|
3
|
+
class NotesApi extends Api {
|
|
4
|
+
constructor(resource) {
|
|
5
|
+
super(resource);
|
|
6
|
+
this.resource = "notes";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async relation(prefix, id, args) {
|
|
10
|
+
const url = `${this.baseUrl}/${prefix}/${id}/${this.resource}${this.getUrlParams(args)}`;
|
|
11
|
+
return await this.unWrap(url);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const Notes = new NotesApi();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Api from "../helpers/api";
|
|
2
|
+
|
|
3
|
+
class OrgsApi extends Api {
|
|
4
|
+
constructor(resource) {
|
|
5
|
+
super(resource);
|
|
6
|
+
this.resource = "orgs";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async stats() {
|
|
10
|
+
const url = `${this._geStatstUrl()}`;
|
|
11
|
+
return await this.get(url);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async publicStats() {
|
|
15
|
+
const url = `${this._geStatstUrl(true)}`;
|
|
16
|
+
return await this.get(url);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_geStatstUrl(isPublic) {
|
|
20
|
+
const endpoint = isPublic ? "pstats" : "stats";
|
|
21
|
+
return `${this.getUrl()}/${endpoint}${this.getUrlParams()}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const Orgs = new OrgsApi();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
|
+
|
|
3
|
+
class SponsorsApi extends Api {
|
|
4
|
+
constructor(resource) {
|
|
5
|
+
super(resource);
|
|
6
|
+
this.resource = 'sponsors';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async map() {
|
|
10
|
+
this.setOrg();
|
|
11
|
+
|
|
12
|
+
if(!this.orgId) throw new Error('No org id provided');
|
|
13
|
+
|
|
14
|
+
const url = `${this.getUrl()}/${this.orgId}/map-data`;
|
|
15
|
+
return await this.get(url);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async profile() {
|
|
19
|
+
this.setOrg();
|
|
20
|
+
|
|
21
|
+
if(!this.orgId) throw new Error('No org id provided');
|
|
22
|
+
|
|
23
|
+
const url = `${this.getUrl()}/${this.orgId}/profile`;
|
|
24
|
+
return await this.get(url);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async plantingStats(args) {
|
|
28
|
+
const url = `${this.getUrl()}/planting-stats${this.getUrlParams(args)}`;
|
|
29
|
+
return await this.get(url);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const Sponsors = new SponsorsApi();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
|
+
|
|
3
|
+
class StatsApi extends Api {
|
|
4
|
+
constructor(resource) {
|
|
5
|
+
super(resource);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async crumb(id) {
|
|
9
|
+
this.resource = 'pstats';
|
|
10
|
+
const url = `${this.getUrl()}/${id}${this.getUrlParams()}`;
|
|
11
|
+
|
|
12
|
+
return await this.get(url);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const Stats = new StatsApi();
|
|
17
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
|
+
|
|
3
|
+
class UserApi extends Api {
|
|
4
|
+
constructor(resource) {
|
|
5
|
+
super(resource);
|
|
6
|
+
this.resource = 'me';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async me() {
|
|
10
|
+
const url = `${this.getUrl()}${this.getUrlParams()}`;
|
|
11
|
+
return await this.get(url);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const User = new UserApi();
|
package/src/helpers/api.js
CHANGED
|
@@ -1,117 +1,209 @@
|
|
|
1
1
|
import { getCookie } from "./cookies";
|
|
2
|
+
import { createParamsStringFromArgs } from "../utils/args";
|
|
3
|
+
import { getSession } from "./session";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Adds the envelope argument to the url
|
|
7
|
+
*
|
|
8
|
+
* @param {string} url
|
|
9
|
+
* @returns {string} url
|
|
10
|
+
*/
|
|
11
|
+
function addEnvelopeParam(url) {
|
|
12
|
+
if (!url || url.includes("_result=1")) return url;
|
|
13
|
+
|
|
14
|
+
const urlHasArgs = url.includes("?");
|
|
15
|
+
const urlEvenlopeArg = urlHasArgs ? "&_result=1" : "?_result=1";
|
|
16
|
+
|
|
17
|
+
return `${url}${urlEvenlopeArg}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Handles how the data should be sent in the fetch method
|
|
22
|
+
*
|
|
23
|
+
* @param {string} method
|
|
24
|
+
* @param {object} body
|
|
25
|
+
* @returns {object} data
|
|
26
|
+
*/
|
|
27
|
+
function getConfig(method, data, as) {
|
|
28
|
+
const isGet = method === "get";
|
|
29
|
+
const isSpoofing = as !== undefined;
|
|
30
|
+
const isFormData = data instanceof FormData;
|
|
31
|
+
const accessToken = `Bearer ${getCookie("access_token")}`;
|
|
32
|
+
|
|
33
|
+
const config = {
|
|
34
|
+
method,
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: accessToken,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (!isFormData) {
|
|
41
|
+
config.headers["Content-Type"] = "application/json";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// TODO: improve this ifs and elses
|
|
45
|
+
if (!isGet) {
|
|
46
|
+
if (!data) data = {};
|
|
47
|
+
|
|
48
|
+
if (isFormData) {
|
|
49
|
+
if (isSpoofing) data.set("_method", as.toUpperCase());
|
|
50
|
+
config.body = data;
|
|
51
|
+
} else {
|
|
52
|
+
if (isSpoofing) data._method = as.toUpperCase();
|
|
53
|
+
config.body = JSON.stringify(data);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return config;
|
|
58
|
+
}
|
|
2
59
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
60
|
+
export default class Api {
|
|
61
|
+
constructor(resource) {
|
|
62
|
+
this.baseUrl = `${process.env.API_VERITREE_URL}/api`;
|
|
63
|
+
this.resource = resource ? resource : "";
|
|
64
|
+
this.orgId = null;
|
|
65
|
+
this.orgType = null;
|
|
66
|
+
}
|
|
6
67
|
|
|
7
68
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {string} url
|
|
69
|
+
*
|
|
10
70
|
* @returns {promise}
|
|
11
71
|
*/
|
|
12
|
-
async
|
|
13
|
-
|
|
14
|
-
|
|
72
|
+
async all(args) {
|
|
73
|
+
const url = `${this.getUrl()}${this.getUrlParams(args)}`;
|
|
74
|
+
return await this.get(url);
|
|
75
|
+
}
|
|
15
76
|
|
|
16
77
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {string}
|
|
19
|
-
* @param {object}
|
|
78
|
+
*
|
|
79
|
+
* @param {string, number} id
|
|
80
|
+
* @param {object} args/params
|
|
20
81
|
* @returns {promise}
|
|
21
82
|
*/
|
|
22
|
-
async
|
|
23
|
-
|
|
24
|
-
|
|
83
|
+
async single(id, args) {
|
|
84
|
+
const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
|
|
85
|
+
return await this.get(url);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
*
|
|
90
|
+
* @param {object} data
|
|
91
|
+
* @returns {promise}
|
|
92
|
+
*/
|
|
93
|
+
async create(data) {
|
|
94
|
+
return await this.post(null, data);
|
|
95
|
+
}
|
|
25
96
|
|
|
26
97
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @param {string} url
|
|
29
|
-
* @param {object} data
|
|
98
|
+
*
|
|
99
|
+
* @param {string} url
|
|
100
|
+
* @param {object} data
|
|
30
101
|
* @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
|
|
31
102
|
* @returns {promise}
|
|
32
103
|
*/
|
|
33
|
-
async update(
|
|
104
|
+
async update(id, data, as = "put") {
|
|
105
|
+
const url = `${this.getUrl(id)}${this.getUrlParams()}`;
|
|
34
106
|
return await this.post(url, data, as);
|
|
35
|
-
}
|
|
107
|
+
}
|
|
36
108
|
|
|
37
109
|
/**
|
|
38
|
-
* Deals with all fetch requests
|
|
39
110
|
*
|
|
40
111
|
* @param {string} url
|
|
41
|
-
* @param {string} method
|
|
42
112
|
* @param {object} data
|
|
43
|
-
* @
|
|
113
|
+
* @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
|
|
114
|
+
* @returns {promise}
|
|
44
115
|
*/
|
|
45
|
-
async
|
|
46
|
-
|
|
47
|
-
|
|
116
|
+
async delete(id) {
|
|
117
|
+
const url = `${this.getUrl(id)}${this.getUrlParams()}`;
|
|
118
|
+
return await this.post(url, null, "delete");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* @param {string} url
|
|
124
|
+
* @returns {promise}
|
|
125
|
+
*/
|
|
126
|
+
async get(url) {
|
|
127
|
+
return await this.unWrap(url);
|
|
128
|
+
}
|
|
48
129
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
130
|
+
/**
|
|
131
|
+
*
|
|
132
|
+
* @param {string} url
|
|
133
|
+
* @param {object} data
|
|
134
|
+
* @returns {promise}
|
|
135
|
+
*/
|
|
136
|
+
async post(url, data, as) {
|
|
137
|
+
if (!url) url = `${this.getUrl()}${this.getUrlParams()}`;
|
|
138
|
+
return await this.unWrap(url, "post", data, as);
|
|
139
|
+
}
|
|
52
140
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
141
|
+
// ----------
|
|
142
|
+
// --
|
|
143
|
+
/**
|
|
144
|
+
*
|
|
145
|
+
* @param {string, number} id
|
|
146
|
+
* @returns
|
|
147
|
+
*/
|
|
148
|
+
getUrl(id) {
|
|
149
|
+
id = id ? `/${id}` : "";
|
|
150
|
+
return `${this.baseUrl}/${this.resource}${id}`;
|
|
151
|
+
}
|
|
58
152
|
|
|
59
153
|
/**
|
|
60
|
-
* Handles how the data should be sent in the fetch method
|
|
61
154
|
*
|
|
62
|
-
* @param {
|
|
63
|
-
* @
|
|
64
|
-
* @returns {object} data
|
|
155
|
+
* @param {object} args
|
|
156
|
+
* @returns {string}
|
|
65
157
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Authorization: accessToken,
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
if(!isFormData) {
|
|
80
|
-
config.headers['Content-Type'] = 'application/json';
|
|
158
|
+
getUrlParams(args) {
|
|
159
|
+
this.setOrg();
|
|
160
|
+
let isOrgLess = false;
|
|
161
|
+
let orgIdParam = "";
|
|
162
|
+
let orgTypeParam = "";
|
|
163
|
+
|
|
164
|
+
// while most of endpoints require an org id and type, some endpoints do not
|
|
165
|
+
if (args && args.length) {
|
|
166
|
+
isOrgLess = Object.hasOwnProperty.call(...args, "orgless");
|
|
81
167
|
}
|
|
82
168
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if(
|
|
86
|
-
if(isPut) data.set('_method', 'PUT');
|
|
87
|
-
config.body = data;
|
|
88
|
-
} else {
|
|
89
|
-
if(isPut) data._method = 'PUT';
|
|
90
|
-
config.body = JSON.stringify(data);
|
|
91
|
-
}
|
|
169
|
+
if (!isOrgLess) {
|
|
170
|
+
if (this.orgId) orgIdParam = `org_id=${this.orgId}`;
|
|
171
|
+
if (this.orgType) orgTypeParam = `&org_type=${this.orgType}`;
|
|
92
172
|
}
|
|
93
173
|
|
|
94
|
-
return
|
|
95
|
-
}
|
|
174
|
+
return `?${orgIdParam}${orgTypeParam}${createParamsStringFromArgs(args)}`;
|
|
175
|
+
}
|
|
96
176
|
|
|
97
177
|
/**
|
|
98
|
-
*
|
|
178
|
+
* Deals with all fetch requests
|
|
99
179
|
*
|
|
100
180
|
* @param {string} url
|
|
101
|
-
* @
|
|
181
|
+
* @param {string} method
|
|
182
|
+
* @param {object} data
|
|
183
|
+
* @returns {object} envelope
|
|
102
184
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return data instanceof FormData;
|
|
114
|
-
},
|
|
115
|
-
};
|
|
185
|
+
async unWrap(url, method = "get", data, as) {
|
|
186
|
+
url = addEnvelopeParam(url);
|
|
187
|
+
const config = getConfig(method, data, as);
|
|
188
|
+
const response = await fetch(url, config);
|
|
189
|
+
|
|
190
|
+
return new Promise((resolve, reject) => {
|
|
191
|
+
if (response.ok && response.status === 204) {
|
|
192
|
+
resolve();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
116
195
|
|
|
117
|
-
|
|
196
|
+
response.json().then((json) => {
|
|
197
|
+
response.ok ? resolve(json) : reject(json);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
setOrg() {
|
|
203
|
+
const session = getSession();
|
|
204
|
+
if (!session) return;
|
|
205
|
+
const { orgId, orgType } = session;
|
|
206
|
+
this.orgId = orgId;
|
|
207
|
+
this.orgType = orgType;
|
|
208
|
+
}
|
|
209
|
+
}
|
package/src/helpers/session.js
CHANGED
package/src/utils/args.js
CHANGED
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
export const createParamsStringFromArgs = (args) => {
|
|
2
|
-
if(!args
|
|
2
|
+
if (!args && typeof args !== 'object' && !Array.isArray(args)) {
|
|
3
|
+
return "";
|
|
4
|
+
}
|
|
3
5
|
|
|
4
6
|
const paramsString = [];
|
|
5
7
|
let arr = [];
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
if(
|
|
9
|
-
for(const key in arg) {
|
|
10
|
-
if(arg[key] === null) return;
|
|
11
|
-
|
|
12
|
-
if(Array.isArray(arg[key])) {
|
|
13
|
-
arr = arg[key].map((item, index) => {
|
|
14
|
-
const param = `${key}[]=${item}`;
|
|
9
|
+
Object.entries(args).forEach(([key, value]) => {
|
|
10
|
+
if (value === null) return;
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
arr = value.map((item, index) => {
|
|
14
|
+
const param = `${key}[]=${item}`;
|
|
15
|
+
return index === 0 ? `${param}` : `&${param}`;
|
|
16
|
+
}).join("");
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
}
|
|
18
|
+
paramsString.push(arr);
|
|
19
|
+
} else {
|
|
20
|
+
if (value !== undefined) {
|
|
21
|
+
paramsString.push(`${key}=${value}`);
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if(!paramsString.length) return '';
|
|
24
|
+
});
|
|
30
25
|
|
|
31
|
-
return `&${paramsString.join(
|
|
32
|
-
}
|
|
26
|
+
return paramsString.length ? `&${paramsString.join("&")}` : "";
|
|
27
|
+
};
|
package/package-lock.json
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import Api from '../helpers/api';
|
|
2
|
-
|
|
3
|
-
export const createCountriesApiService = () => {
|
|
4
|
-
const resource = 'countries';
|
|
5
|
-
|
|
6
|
-
const get = {
|
|
7
|
-
async all() {
|
|
8
|
-
const url = _getUrl();
|
|
9
|
-
return await Api.get(url);
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
async specific(countriId) {
|
|
13
|
-
const url = `${_getUrl()}/${countriId}`;
|
|
14
|
-
return await Api.get(url);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const stats = {
|
|
19
|
-
async get(countryId) {
|
|
20
|
-
const type = countryId ? `${countryId}` : 'global';
|
|
21
|
-
const url = `${_getUrl()}/${type}/stats`;
|
|
22
|
-
|
|
23
|
-
return await Api.get(url);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const _getUrl = () => {
|
|
28
|
-
return `${Api.baseUrl}/${resource}`;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
get,
|
|
33
|
-
stats
|
|
34
|
-
};
|
|
35
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import Api from "../helpers/api";
|
|
2
|
-
import { getSession } from "../helpers/session";
|
|
3
|
-
|
|
4
|
-
export const createFieldUpdateVerificationsApiService = () => {
|
|
5
|
-
const resource = `field-update-verifications`;
|
|
6
|
-
const { orgId, orgType } = getSession();
|
|
7
|
-
|
|
8
|
-
if (!orgId && !orgType) {
|
|
9
|
-
throw new Error('Organization id and type are required');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {object} data
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
const post = (data) => {
|
|
18
|
-
const url = `${_getUrl()}?${_getParams()}`;
|
|
19
|
-
|
|
20
|
-
return Api.post(url, data);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const _getUrl = () => {
|
|
24
|
-
return `${Api.baseUrl}/${resource}`;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const _getParams = () => {
|
|
28
|
-
return `org_id=${orgId}&org_type=${orgType}`;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
post,
|
|
33
|
-
};
|
|
34
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import Api from "../helpers/api";
|
|
2
|
-
import { getSession } from "../helpers/session";
|
|
3
|
-
import { createParamsStringFromArgs } from "../utils/args";
|
|
4
|
-
|
|
5
|
-
export const createFieldUpdatesApiService = () => {
|
|
6
|
-
const resource = `field-updates`;
|
|
7
|
-
const { orgId, orgType } = getSession();
|
|
8
|
-
|
|
9
|
-
if (!orgId && !orgType) {
|
|
10
|
-
throw new Error('Organization id and type are required');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const get = {
|
|
14
|
-
async all() {
|
|
15
|
-
const url = `${_getUrl()}?${_getParams(arguments)}`;
|
|
16
|
-
|
|
17
|
-
return await Api.get(url);
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
async specific(id) {
|
|
21
|
-
const url = `${_getUrl()}/${id}?${_getParams()}`;
|
|
22
|
-
|
|
23
|
-
return await Api.get(url);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
* @param {object} data
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
const post = (data) => {
|
|
33
|
-
const url = `${_getUrl()}?${_getParams()}`;
|
|
34
|
-
|
|
35
|
-
return Api.post(url, data);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @param {string} fieldUpdateId
|
|
41
|
-
* @param {object} data
|
|
42
|
-
* @returns
|
|
43
|
-
*/
|
|
44
|
-
const update = (fieldUpdateId, data) => {
|
|
45
|
-
const url = `${_getUrl()}/${fieldUpdateId}?${_getParams()}`;
|
|
46
|
-
|
|
47
|
-
return Api.post(url, data);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
52
|
-
*/
|
|
53
|
-
const remove = {
|
|
54
|
-
async img(fieldUpdateId, data) {
|
|
55
|
-
const url = `${_getUrl()}/${fieldUpdateId}/images/detach?${_getParams()}`;
|
|
56
|
-
|
|
57
|
-
return await Api.post(url, data);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const _getUrl = () => {
|
|
62
|
-
return `${Api.baseUrl}/${resource}`;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const _getParams = (args) => {
|
|
66
|
-
const paramsString = createParamsStringFromArgs(args);
|
|
67
|
-
|
|
68
|
-
return `org_id=${orgId}&org_type=${orgType}${paramsString}`;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
get,
|
|
73
|
-
post,
|
|
74
|
-
update,
|
|
75
|
-
remove
|
|
76
|
-
};
|
|
77
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import Api from '../helpers/api';
|
|
2
|
-
import { createParamsStringFromArgs } from '../utils/args';
|
|
3
|
-
import { getSession } from "../helpers/session";
|
|
4
|
-
|
|
5
|
-
export const createForestTypesApiService = () => {
|
|
6
|
-
const resource = 'forest-types';
|
|
7
|
-
const { orgId, orgType } = getSession();
|
|
8
|
-
|
|
9
|
-
if (!orgId && !orgType) {
|
|
10
|
-
throw new Error('Organization id and type are required');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const get = {
|
|
14
|
-
/**
|
|
15
|
-
* @param {object} arguments
|
|
16
|
-
* @returns {object} envelope
|
|
17
|
-
*/
|
|
18
|
-
async all() {
|
|
19
|
-
const url = `${_getUrl()}?${_getParams(arguments)}`;
|
|
20
|
-
|
|
21
|
-
return await Api.get(url);
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @param {number/string} id
|
|
26
|
-
* @returns {object} envelope
|
|
27
|
-
*/
|
|
28
|
-
async specific(id) {
|
|
29
|
-
const url = `${_getUrl()}/${id}?${_getParams()}`;
|
|
30
|
-
|
|
31
|
-
return await Api.get(url);
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const _getUrl = () => {
|
|
36
|
-
return `${Api.baseUrl}/${resource}`;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const _getParams = (args) => {
|
|
40
|
-
const paramsString = createParamsStringFromArgs(args);
|
|
41
|
-
|
|
42
|
-
return `org_id=${orgId}&org_type=${orgType}${paramsString}`;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
get,
|
|
47
|
-
};
|
|
48
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import Api from '../helpers/api';
|
|
2
|
-
import { getSession } from "../helpers/session";
|
|
3
|
-
import { createParamsStringFromArgs } from '../utils/args';
|
|
4
|
-
|
|
5
|
-
export const createFormSubmissionsApiService = () => {
|
|
6
|
-
const resource = 'form-submissions';
|
|
7
|
-
const { orgId, orgType } = getSession();
|
|
8
|
-
|
|
9
|
-
if (!orgId && !orgType) {
|
|
10
|
-
throw new Error('Organization id and type are required');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const get = {
|
|
14
|
-
async all() {
|
|
15
|
-
const url = `${_getUrl()}?${_getParams(arguments)}`;
|
|
16
|
-
return await Api.get(url);
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const _getUrl = () => {
|
|
21
|
-
return `${Api.baseUrl}/${resource}`;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const _getParams = (args) => {
|
|
25
|
-
const paramsString = createParamsStringFromArgs(args);
|
|
26
|
-
|
|
27
|
-
return `org_id=${orgId}&org_type=${orgType}${paramsString}`;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
get,
|
|
32
|
-
};
|
|
33
|
-
};
|
package/src/services/forms.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import Api from '../helpers/api';
|
|
2
|
-
|
|
3
|
-
export const createFormApiService = (orgId, orgType) => {
|
|
4
|
-
if (!orgId && !orgType) throw new Error('orgId and orgType are required');
|
|
5
|
-
const resource = 'orgs';
|
|
6
|
-
|
|
7
|
-
const get = {
|
|
8
|
-
async all(page = 1, pageSize = 10) {
|
|
9
|
-
const url = `${_getUrl()}/${orgId}/forms?${_getParams(page, pageSize)}`;
|
|
10
|
-
return await Api.get(url);
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
async specific(formId) {
|
|
14
|
-
const url = `${_getUrl()}/${orgId}/forms/${formId}?${_getParams()}`;
|
|
15
|
-
return await Api.get(url);
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const _getUrl = () => {
|
|
20
|
-
return `${Api.baseUrl}/${resource}`;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const _getParams = (page, pageSize) => {
|
|
24
|
-
const paramPageSize = pageSize ? `&page_size=${pageSize}` : '';
|
|
25
|
-
const paramPage = page ? `&page=${page}` : '';
|
|
26
|
-
|
|
27
|
-
return `org_type=${orgType}${paramPageSize}${paramPage}`;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
get,
|
|
32
|
-
};
|
|
33
|
-
};
|
package/src/services/images.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import Api from "../helpers/api";
|
|
2
|
-
import { getSession } from "../helpers/session";
|
|
3
|
-
import { createParamsStringFromArgs } from "../utils/args";
|
|
4
|
-
|
|
5
|
-
export const createImagesApiService = () => {
|
|
6
|
-
const resource = "images";
|
|
7
|
-
const { orgId, orgType } = getSession();
|
|
8
|
-
|
|
9
|
-
if (!orgId && !orgType) {
|
|
10
|
-
throw new Error("Organization id and type are required");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const get = {
|
|
14
|
-
async all() {
|
|
15
|
-
const url = `${_getUrl()}?${_getParams(arguments)}`;
|
|
16
|
-
return await Api.get(url);
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
async specific(id) {
|
|
20
|
-
const url = `${_getUrl()}/${id}?${_getParams()}`;
|
|
21
|
-
|
|
22
|
-
return await Api.get(url);
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const _getUrl = () => {
|
|
27
|
-
return `${Api.baseUrl}/${resource}`;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const _getParams = (args) => {
|
|
31
|
-
const paramsString = createParamsStringFromArgs(args);
|
|
32
|
-
|
|
33
|
-
return `org_id=${orgId}&org_type=${orgType}${paramsString}`;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
get,
|
|
38
|
-
};
|
|
39
|
-
};
|
package/src/services/me.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import Api from '../helpers/api';
|
|
2
|
-
|
|
3
|
-
export const createMeApiService = () => {
|
|
4
|
-
const resource = 'me';
|
|
5
|
-
|
|
6
|
-
const get = {
|
|
7
|
-
async me() {
|
|
8
|
-
const url = _getUrl();
|
|
9
|
-
return await Api.get(url);
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const _getUrl = () => {
|
|
14
|
-
return `${Api.baseUrl}/${resource}`;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
get,
|
|
19
|
-
};
|
|
20
|
-
};
|
package/src/services/orgs.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import Api from '../helpers/api';
|
|
2
|
-
|
|
3
|
-
export const createOrgsApiService = (orgId, orgType) => {
|
|
4
|
-
if (!orgId && !orgType) throw new Error('No org id and/or type provided');
|
|
5
|
-
const resource = 'orgs';
|
|
6
|
-
|
|
7
|
-
// filter for stats data
|
|
8
|
-
const stats = {
|
|
9
|
-
async get(isPublic) {
|
|
10
|
-
const endpoint = _getStatsEndpoint(isPublic);
|
|
11
|
-
const url = `${_getUrl()}/${endpoint}?${_getUrlParams()}`;
|
|
12
|
-
return await Api.get(url);
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const _getStatsEndpoint = (isPublic) => {
|
|
17
|
-
return isPublic ? 'pstats' : 'stats';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const _getUrl = () => {
|
|
21
|
-
return `${Api.baseUrl}/${resource}`;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const _getUrlParams = () => {
|
|
25
|
-
return `org_id=${orgId}&org_type=${orgType}`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
stats,
|
|
30
|
-
};
|
|
31
|
-
};
|
package/src/services/regions.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import Api from "../helpers/api";
|
|
2
|
-
import { getSession } from "../helpers/session";
|
|
3
|
-
import { createParamsStringFromArgs } from "../utils/args";
|
|
4
|
-
|
|
5
|
-
export const createRegionsApiService = () => {
|
|
6
|
-
const resource = "regions";
|
|
7
|
-
const { orgId, orgType } = getSession();
|
|
8
|
-
|
|
9
|
-
if (!orgId && !orgType) {
|
|
10
|
-
throw new Error("Organization id and type are required");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const get = {
|
|
14
|
-
async all() {
|
|
15
|
-
const url = `${_getUrl()}?${_getParams(arguments)}`;
|
|
16
|
-
|
|
17
|
-
return await Api.get(url);
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const post = (data) => {
|
|
22
|
-
const url = `${_getUrl()}?${_getParams()}`;
|
|
23
|
-
|
|
24
|
-
return Api.post(url, data);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const _getUrl = () => {
|
|
28
|
-
return `${Api.baseUrl}/${resource}`;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const _getParams = (args) => {
|
|
32
|
-
const paramsString = createParamsStringFromArgs(args)
|
|
33
|
-
|
|
34
|
-
return `org_id=${orgId}&org_type=${orgType}${paramsString}`;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
get,
|
|
39
|
-
post,
|
|
40
|
-
};
|
|
41
|
-
};
|
package/src/services/sponsors.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import Api from '../helpers/api';
|
|
2
|
-
|
|
3
|
-
export const createSponsorsApiService = (orgId) => {
|
|
4
|
-
if (!orgId) throw new Error('No org id provided');
|
|
5
|
-
const resource = 'sponsors';
|
|
6
|
-
|
|
7
|
-
// filter for map data
|
|
8
|
-
const map = {
|
|
9
|
-
async get() {
|
|
10
|
-
const url = `${_getUrl()}/${orgId}/map-data`;
|
|
11
|
-
return await Api.get(url);
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// filter for profile
|
|
16
|
-
const profile = {
|
|
17
|
-
async get() {
|
|
18
|
-
const url = `${_getUrl()}/${orgId}/profile`;
|
|
19
|
-
return await Api.get(url);
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const _getUrl = () => {
|
|
24
|
-
return `${Api.baseUrl}/${resource}`;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
map,
|
|
29
|
-
profile,
|
|
30
|
-
};
|
|
31
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import Api from '../helpers/api';
|
|
2
|
-
|
|
3
|
-
export const createSubdomainsApiService = () => {
|
|
4
|
-
const resource = 'subdomains';
|
|
5
|
-
|
|
6
|
-
const get = {
|
|
7
|
-
/**
|
|
8
|
-
* Gets org data related to subdomain
|
|
9
|
-
*
|
|
10
|
-
* @param {string} id (name or id)
|
|
11
|
-
* @returns {object} evenlop
|
|
12
|
-
*/
|
|
13
|
-
async specific(id) {
|
|
14
|
-
const url = `${_getUrl()}/${id}`;
|
|
15
|
-
return await Api.get(url);
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
function _getUrl() {
|
|
20
|
-
return `${Api.baseUrl}/${resource}`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
get,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import Api from "../helpers/api";
|
|
2
|
-
import { getSession } from "../helpers/session";
|
|
3
|
-
import { createParamsStringFromArgs } from "../utils/args";
|
|
4
|
-
|
|
5
|
-
export const createSubsiteTypesApiService = () => {
|
|
6
|
-
const resource = "subsite-types";
|
|
7
|
-
const { orgId, orgType } = getSession();
|
|
8
|
-
|
|
9
|
-
if (!orgId && !orgType) {
|
|
10
|
-
throw new Error("Organization id and type are required");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const get = {
|
|
14
|
-
/**
|
|
15
|
-
* @returns {obj} envelope
|
|
16
|
-
*/
|
|
17
|
-
async all() {
|
|
18
|
-
const url = `${_getUrl()}?${_getUrlParams(arguments)}`;
|
|
19
|
-
|
|
20
|
-
return await Api.get(url);
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Gets a speficific subsite of an organization
|
|
25
|
-
*
|
|
26
|
-
* @param {number/string} id
|
|
27
|
-
* @param {number/string} page
|
|
28
|
-
* @returns {object} envelope
|
|
29
|
-
*/
|
|
30
|
-
async specific(id) {
|
|
31
|
-
const url = `${_getUrl()}/${id}?${_getUrlParams()}`;
|
|
32
|
-
|
|
33
|
-
return await Api.get(url);
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
async stats(id) {
|
|
37
|
-
const url = `${_getUrl()}/${id}/stats`;
|
|
38
|
-
|
|
39
|
-
return await Api.get(url);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const post = (data) => {
|
|
44
|
-
const url = `${_getUrl()}?${_getUrlParams()}`;
|
|
45
|
-
|
|
46
|
-
return Api.post(url, data);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const update = (id, data) => {
|
|
50
|
-
const url = `${_getUrl()}/${id}?${_getUrlParams()}`;
|
|
51
|
-
|
|
52
|
-
return Api.update(url, data);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const _getUrl = () => {
|
|
56
|
-
return `${Api.baseUrl}/${resource}`;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const _getUrlParams = (args) => {
|
|
60
|
-
const paramsString = createParamsStringFromArgs(args);
|
|
61
|
-
|
|
62
|
-
return `org_id=${orgId}&org_type=${orgType}${paramsString}`;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
get,
|
|
67
|
-
post,
|
|
68
|
-
update
|
|
69
|
-
};
|
|
70
|
-
};
|
package/src/services/subsites.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import Api from "../helpers/api";
|
|
2
|
-
import { getSession } from "../helpers/session";
|
|
3
|
-
import { createParamsStringFromArgs } from "../utils/args";
|
|
4
|
-
|
|
5
|
-
export const createSubsitesApiService = () => {
|
|
6
|
-
const resource = "subsites";
|
|
7
|
-
const { orgId, orgType } = getSession();
|
|
8
|
-
|
|
9
|
-
if (!orgId && !orgType) {
|
|
10
|
-
throw new Error("Organization id and type are required");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const get = {
|
|
14
|
-
/**
|
|
15
|
-
* @returns {obj} envelope
|
|
16
|
-
*/
|
|
17
|
-
async all() {
|
|
18
|
-
const url = `${_getUrl()}?${_getUrlParams(arguments)}`;
|
|
19
|
-
|
|
20
|
-
return await Api.get(url);
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Gets a speficific subsite of an organization
|
|
25
|
-
*
|
|
26
|
-
* @param {number/string} id
|
|
27
|
-
* @param {number/string} page
|
|
28
|
-
* @returns {object} envelope
|
|
29
|
-
*/
|
|
30
|
-
async specific(id) {
|
|
31
|
-
const url = `${_getUrl()}/${id}?${_getUrlParams()}`;
|
|
32
|
-
|
|
33
|
-
return await Api.get(url);
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
async stats(id) {
|
|
37
|
-
const url = `${_getUrl()}/${id}/stats`;
|
|
38
|
-
|
|
39
|
-
return await Api.get(url);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const post = (data) => {
|
|
44
|
-
const url = `${_getUrl()}?${_getUrlParams()}`;
|
|
45
|
-
|
|
46
|
-
return Api.post(url, data);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const update = (id, data) => {
|
|
50
|
-
const url = `${_getUrl()}/${id}?${_getUrlParams()}`;
|
|
51
|
-
|
|
52
|
-
return Api.update(url, data);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const _getUrl = () => {
|
|
56
|
-
return `${Api.baseUrl}/${resource}`;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const _getUrlParams = (args) => {
|
|
60
|
-
const paramsString = createParamsStringFromArgs(args);
|
|
61
|
-
|
|
62
|
-
return `org_id=${orgId}&org_type=${orgType}${paramsString}`;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
get,
|
|
67
|
-
post,
|
|
68
|
-
update
|
|
69
|
-
};
|
|
70
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import Api from '../helpers/api';
|
|
2
|
-
|
|
3
|
-
export const createTreeOrdersApiService = (orgId, orgType) => {
|
|
4
|
-
const resource = 'tree-orders';
|
|
5
|
-
|
|
6
|
-
const get = {
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {number/string} page
|
|
10
|
-
* @param {number/string} pageSize
|
|
11
|
-
* @returns {object} envelope
|
|
12
|
-
*/
|
|
13
|
-
async all(page = 1, pageSize = 10) {
|
|
14
|
-
const url = `${_getUrl()}?${_getUrlParams(page, pageSize)}`;
|
|
15
|
-
return await Api.get(url);
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param {number/string} id
|
|
21
|
-
* @param {number/string} page
|
|
22
|
-
* @param {number/string} pageSize
|
|
23
|
-
* @returns {object} envelope
|
|
24
|
-
*/
|
|
25
|
-
async specific(id, page = 1, pageSize = 10) {
|
|
26
|
-
const url = `${_getUrl()}/${id}?${_getUrlParams(page, pageSize)}`;
|
|
27
|
-
return await Api.get(url);
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const _getUrl = () => {
|
|
32
|
-
return `${Api.baseUrl}/${resource}`;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const _getUrlParams = (page, pageSize) => {
|
|
36
|
-
return `org_id=${orgId}&org_type=${orgType}&page=${page}&page_size=${pageSize}&include=tree_allocations`;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
get,
|
|
41
|
-
};
|
|
42
|
-
};
|