@veritree/services 2.65.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 +1 -1
- package/src/helpers/relations.js +58 -8
package/package.json
CHANGED
package/src/helpers/relations.js
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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
|
|