@veritree/services 1.5.0-4 → 1.5.0-7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "1.5.0-4",
3
+ "version": "1.5.0-7",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,4 +1,6 @@
1
1
  import Api from "../helpers/api";
2
+ import Team from "../helpers/team";
3
+ import { getSession } from "../helpers/session";
2
4
 
3
5
  class OrgsApi extends Api {
4
6
  constructor(resource) {
@@ -6,6 +8,11 @@ class OrgsApi extends Api {
6
8
  this.resource = "orgs";
7
9
  }
8
10
 
11
+ users() {
12
+ const { orgId } = getSession();
13
+ return Team(this, orgId);
14
+ }
15
+
9
16
  async roles(orgId, params) {
10
17
  const url = `${this.getUrl()}/${orgId}/roles${this.getUrlParams(params)}`;
11
18
  return await this.get(url);
@@ -90,8 +90,8 @@ export default class Api {
90
90
  * @param {object} data
91
91
  * @returns {promise}
92
92
  */
93
- async create(data, args) {
94
- return await this.post(null, data, args);
93
+ async create(data) {
94
+ return await this.post(null, data);
95
95
  }
96
96
 
97
97
  /**
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Creates an abstract team object that can be used
3
+ * for CRUD operations related to an org users.
4
+ *
5
+ * @param {object} api
6
+ * @param {number} id
7
+ * @returns {object}
8
+ */
9
+ const Team = (api, id) => {
10
+ let url = `${api.baseUrl}/${api.resource}/${id}/users`;
11
+
12
+ const all = async (args) => {
13
+ url = `${url}${api.getUrlParams(args)}`;
14
+ return await api.get(url);
15
+ };
16
+
17
+ const single = async (userId, args) => {
18
+ url = `${url}/${userId}${api.getUrlParams(args)}`;
19
+ return await api.get(url);
20
+ };
21
+
22
+ const create = async (data) => {
23
+ url = `${url}${api.getUrlParams()}`;
24
+ return await api.post(url, data);
25
+ }
26
+
27
+ const update = async (userId, data) => {
28
+ url = `${url}/${userId}${api.getUrlParams()}`;
29
+ return await api.update(url, data, 'patch');
30
+ }
31
+
32
+ const remove = async (userId) => {
33
+ url = `${url}/${userId}${api.getUrlParams()}`;
34
+ return await api.delete(url);
35
+ }
36
+
37
+ return {
38
+ all,
39
+ single,
40
+ create,
41
+ update,
42
+ delete: remove
43
+ };
44
+ };
45
+
46
+ export default Team;