@veritree/services 2.63.0 → 2.65.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.63.0",
3
+ "version": "2.65.0",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,19 +1,18 @@
1
- import Api from "../helpers/api";
1
+ import Api from '../helpers/api';
2
2
 
3
3
  class InventoryApi extends Api {
4
4
  constructor(resource) {
5
5
  super(resource);
6
- this.resource = "inventory";
6
+ this.resource = 'inventory';
7
7
  }
8
8
 
9
9
  // org type can be organizations, resellers, sponsors
10
- async all(orgType, orgId) {
11
- const url = `${this.baseUrl}/${orgType}/${orgId}/${
12
- this.resource
13
- }`
10
+ async all(orgType, orgId, args) {
11
+ const params = this.getUrlParams({ ...args, orgless: true });
12
+ const url = `${this.baseUrl}/${orgType}/${orgId}/${this.resource}${params}`;
14
13
 
15
- return await this.get(url);
14
+ return await this.get(url, args);
16
15
  }
17
16
  }
18
17
 
19
- export const Inventory = new InventoryApi();
18
+ export const Inventory = new InventoryApi();
@@ -31,18 +31,94 @@ class TasksApi extends Api {
31
31
  const attach = async (data) => {
32
32
  url = `${url}/users-attach${this.getUrlParams()}`;
33
33
  return await this.post(url, data);
34
- }
34
+ };
35
35
 
36
36
  const detach = async (data) => {
37
37
  url = `${url}/users-detach${this.getUrlParams()}`;
38
38
  return await this.post(url, data);
39
- }
39
+ };
40
40
 
41
41
  return {
42
42
  attach,
43
- detach
44
- }
43
+ detach,
44
+ };
45
+ }
46
+
47
+ /**
48
+ * Returns a set of functions for interacting with task categories.
49
+ * @returns {Object} Object containing functions for CRUD operations on task categories.
50
+ */
51
+ categories() {
52
+ /**
53
+ * Generates a URL for task categories based on the provided organization ID and category ID.
54
+ * @param {string} orgId - The ID of the organization.
55
+ * @param {string|null} [categoryId] - The ID of the category (optional).
56
+ * @param {Object|null} [params] - Additional query parameters (optional).
57
+ * @returns {string} The generated URL.
58
+ */
59
+ const generateUrl = (orgId, categoryId, params) => {
60
+ const queryParams = this.getUrlParams(params);
61
+
62
+ if (categoryId) {
63
+ return `${this.baseUrl}/task-categories/${categoryId}${queryParams}`;
64
+ } else {
65
+ return `${this.baseUrl}/organizations/${orgId}/task-categories${queryParams}`;
66
+ }
67
+ };
68
+
69
+ /**
70
+ * Retrieves all task categories for a given organization.
71
+ * @param {string} orgId - The ID of the organization.
72
+ * @param {Object|null} [params] - Additional query parameters (optional).
73
+ * @returns {Promise} A promise that resolves with the list of task categories.
74
+ */
75
+ const all = async (orgId, params) => {
76
+ const url = generateUrl(orgId, null, params);
77
+ return await this.get(url);
78
+ };
79
+
80
+ /**
81
+ * Creates a new task category for a given organization.
82
+ * @param {string} orgId - The ID of the organization.
83
+ * @param {Object} data - The data for creating the task category.
84
+ * @param {Object|null} [params] - Additional query parameters (optional).
85
+ * @returns {Promise} A promise that resolves with the created task category.
86
+ */
87
+ const create = async (orgId, data, params) => {
88
+ const url = generateUrl(orgId, null, params);
89
+ return await this.post(url, data);
90
+ };
91
+
92
+ /**
93
+ * Updates a task category.
94
+ * @param {string|null} categoryId - The ID of the category to be updated.
95
+ * @param {Object} data - The data to update the task category with.
96
+ * @param {Object|null} [params] - Additional query parameters (optional).
97
+ * @returns {Promise} A promise that resolves with the updated task category.
98
+ */
99
+ const update = async (categoryId, data, params) => {
100
+ const url = generateUrl(null, categoryId, params);
101
+ return await this.post(url, data, "patch");
102
+ };
103
+
104
+ /**
105
+ * Deletes a task category.
106
+ * @param {string|null} categoryId - The ID of the category to be deleted.
107
+ * @param {Object|null} [params] - Additional query parameters (optional).
108
+ * @returns {Promise} A promise that resolves when the category is deleted.
109
+ */
110
+ const remove = async (categoryId, params) => {
111
+ const url = generateUrl(null, categoryId, params);
112
+ return await this.post(url, null, 'delete');
113
+ };
114
+
115
+ return {
116
+ all,
117
+ create,
118
+ update,
119
+ delete: remove,
120
+ };
45
121
  }
46
122
  }
47
123
 
48
- export const Tasks = new TasksApi();
124
+ export const Tasks = new TasksApi();