@veritree/services 2.64.0 → 2.66.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.64.0",
3
+ "version": "2.66.0",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -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();
@@ -1,31 +1,81 @@
1
+ /**
2
+ * Creates a Relations object to handle API relations.
3
+ * @param {object} api - The API object used for making API calls.
4
+ * @param {string} relationPrefix - The prefix for relation endpoints.
5
+ * @param {string} relationId - The identifier for the relation.
6
+ * @returns {object} The Relations object.
7
+ */
1
8
  const Relations = (api, relationPrefix, relationId) => {
2
9
  let url = `${api.baseUrl}/${relationPrefix}/${relationId}/${api.resource}`;
3
10
 
4
- const all = async (args) => {
5
- url = `${url}${api.getUrlParams(args)}`;
11
+ /**
12
+ * Retrieves all tags.
13
+ * @param {object} params - Additional parameters for the request.
14
+ * @returns {Promise<object>} A promise that resolves with the response data.
15
+ */
16
+ const all = async (params) => {
17
+ url = `${url}${api.getUrlParams(params)}`;
6
18
  return await api.get(url);
7
19
  };
8
20
 
9
- const single = async (id, args) => {
10
- url = `${url}/${id}${api.getUrlParams(args)}`;
21
+ /**
22
+ * Retrieves a single tag by ID.
23
+ * @param {string} tagId - The ID of the tag to retrieve.
24
+ * @param {object} params - Additional parameters for the request.
25
+ * @returns {Promise<object>} A promise that resolves with the response data.
26
+ */
27
+ const single = async (tagId, params) => {
28
+ url = `${url}/${tagId}${api.getUrlParams(params)}`;
11
29
  return await api.get(url);
12
30
  };
13
31
 
14
- const attach = async (id, data, args) => {
15
- url = `${url}/${id}/attach${api.getUrlParams(args)}`;
32
+ /**
33
+ * Attaches a tag to a resource.
34
+ * @param {string} tagId - The ID of the tag to attach.
35
+ * @param {object} data - The data to send with the request.
36
+ * @param {object} params - Additional parameters for the request.
37
+ * @returns {Promise<object>} A promise that resolves with the response data.
38
+ */
39
+ const attach = async (tagId, data, params) => {
40
+ url = `${url}/${tagId}/attach${api.getUrlParams(params)}`;
16
41
  return await api.post(url, data);
17
42
  };
18
43
 
19
- const detach = async (id, args) => {
20
- url = `${url}/${id}/detach${api.getUrlParams(args)}`;
44
+ /**
45
+ * Detaches a tag from a resource.
46
+ * @param {string} tagId - The ID of the tag to detach.
47
+ * @param {object} params - Additional parameters for the request.
48
+ * @returns {Promise<object>} A promise that resolves with the response data.
49
+ */
50
+ const detach = async (tagId, params) => {
51
+ url = `${url}/${tagId}/detach${api.getUrlParams(params)}`;
21
52
  return await api.post(url, null, "delete");
22
53
  };
23
54
 
55
+ /**
56
+ * Retrieves usable tags.
57
+ * @param {object} params - Additional parameters for the request.
58
+ * @returns {Promise<object>} A promise that resolves with the response data.
59
+ */
60
+ const usable = async (params) => {
61
+ url = `${
62
+ api.baseUrl
63
+ }/${relationPrefix}/${relationId}/usable-tags${api.getUrlParams(params)}`;
64
+ return await api.get(url);
65
+ };
66
+
67
+ const attached = async (params) => {
68
+ url = `${url}/${api.getUrlParams(params)}`;
69
+ return await api.get(url);
70
+ };
71
+
24
72
  return {
25
73
  all,
74
+ attached,
26
75
  single,
27
76
  attach,
28
77
  detach,
78
+ usable,
29
79
  };
30
80
  };
31
81