@veritree/services 1.0.0-1 → 1.0.0-2
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/helpers/api-v2.js +15 -19
package/package.json
CHANGED
package/src/helpers/api-v2.js
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { getCookie } from "./cookies";
|
|
2
|
-
import { getSession } from "./session";
|
|
3
2
|
import { createParamsStringFromArgs } from "../utils/args";
|
|
3
|
+
import { getSession } from "./session";
|
|
4
4
|
|
|
5
|
-
export default function Api(resource) {
|
|
5
|
+
export default function Api(resource, session) {
|
|
6
6
|
const baseUrl = `${process.env.API_VERITREE_URL}/api`;
|
|
7
|
-
const session = getSession();
|
|
8
|
-
if(!session) return;
|
|
9
|
-
const { orgId, orgType } = session;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!orgId && !orgType) {
|
|
13
|
-
throw new Error("Organization id and type are required");
|
|
14
|
-
}
|
|
15
7
|
|
|
16
8
|
/**
|
|
17
|
-
*
|
|
9
|
+
*
|
|
18
10
|
* @returns {promise}
|
|
19
11
|
*/
|
|
20
12
|
this.all = async function () {
|
|
@@ -23,8 +15,8 @@ export default function Api(resource) {
|
|
|
23
15
|
};
|
|
24
16
|
|
|
25
17
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @param {string, number} id
|
|
18
|
+
*
|
|
19
|
+
* @param {string, number} id
|
|
28
20
|
* @returns {promise}
|
|
29
21
|
*/
|
|
30
22
|
this.single = async function (id) {
|
|
@@ -33,8 +25,8 @@ export default function Api(resource) {
|
|
|
33
25
|
};
|
|
34
26
|
|
|
35
27
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @param {object} data
|
|
28
|
+
*
|
|
29
|
+
* @param {object} data
|
|
38
30
|
* @returns {promise}
|
|
39
31
|
*/
|
|
40
32
|
this.create = async function (data) {
|
|
@@ -49,7 +41,7 @@ export default function Api(resource) {
|
|
|
49
41
|
* @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
|
|
50
42
|
* @returns {promise}
|
|
51
43
|
*/
|
|
52
|
-
this.update = async function (id, data, as =
|
|
44
|
+
this.update = async function (id, data, as = "put") {
|
|
53
45
|
const url = `${this.getUrl()}/${id}?${this.getUrlParams()}`;
|
|
54
46
|
return await this.post(url, data, as);
|
|
55
47
|
};
|
|
@@ -58,11 +50,15 @@ export default function Api(resource) {
|
|
|
58
50
|
// --
|
|
59
51
|
this.getUrl = () => {
|
|
60
52
|
return `${baseUrl}/${resource}`;
|
|
61
|
-
}
|
|
53
|
+
};
|
|
62
54
|
|
|
63
55
|
this.getUrlParams = (args) => {
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
const { orgId, orgType } = getSession();
|
|
57
|
+
|
|
58
|
+
return `org_id=${orgId}&org_type=${orgType}${createParamsStringFromArgs(
|
|
59
|
+
args
|
|
60
|
+
)}`;
|
|
61
|
+
};
|
|
66
62
|
|
|
67
63
|
/**
|
|
68
64
|
*
|