@docbrasil/api-systemmanager 1.0.84 → 1.0.86

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.
@@ -142,6 +142,50 @@ class Process {
142
142
  throw ex;
143
143
  }
144
144
  }
145
+
146
+ /**
147
+ * @author CloudBrasil <abernardo.br@gmail.com>
148
+ * @description Get the search info of a organization process
149
+ * @param {object} params Params to get search info
150
+ * @param {string} params.orgProcessId The id of an organization process (_id database);
151
+ * @param {string} params.orgId Organization id (_id database);
152
+ * @param {string} session Session, token JWT
153
+ * @return {Promise} the search info result
154
+ * @return {string} name the name of the organization process
155
+ * @return {object} processIndexFields the list of fields to index
156
+ * @return {object} processParticipantsGroup the permissions in this organization process
157
+ * @return {object} stepsProperties the organization process steps properties
158
+ * @return {string} _id the same organization id
159
+ * @
160
+ * @public
161
+ * @async
162
+ * @example
163
+ *
164
+ * const API = require('@docbrasil/api-systemmanager');
165
+ * const api = new API();
166
+ * const params = {
167
+ * orgProcessId: '5dadd01dc4af3941d42f8c67',
168
+ * orgId: '5edd11c46b6ce9729c2c297c',
169
+ * }
170
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
171
+ * const retSearchInfo = await api.user.process.getOrgProcessSearchInfo(params, session);
172
+ */
173
+ async getOrgProcessSearchInfo(params, session) {
174
+ const self = this;
175
+
176
+ try {
177
+ Joi.assert(params, Joi.object().required());
178
+ Joi.assert(params.orgProcessId, Joi.string().required());
179
+ Joi.assert(params.orgId, Joi.string().required());
180
+ Joi.assert(session, Joi.string().required());
181
+
182
+ const {orgProcessId, orgId} = params;
183
+ const apiCall = self._client.get(`/organizations/${orgId}/orgprocess/${orgProcessId}/search/info`, self._setHeader(session));
184
+ return self._returnData(await apiCall);
185
+ } catch (ex) {
186
+ throw ex;
187
+ }
188
+ }
145
189
  }
146
190
 
147
191
  export default Process;
package/api/user/task.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import _ from 'lodash';
2
2
  import Boom from '@hapi/boom';
3
3
  import Joi from 'joi';
4
+ import TaskAvailable from './task_available';
4
5
 
5
6
  /**
6
7
  * Class for task, permission user
@@ -15,6 +16,7 @@ class Task {
15
16
  const self = this;
16
17
  self.parent = options.parent;
17
18
  self._client = self.parent.dispatch.getClient();
19
+ self.available = new TaskAvailable(options);
18
20
  }
19
21
 
20
22
  /**
@@ -0,0 +1,135 @@
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+
5
+ /**
6
+ * Class for available tasks, permission user
7
+ * @class
8
+ */
9
+ class TaskAvailable {
10
+
11
+ constructor(options) {
12
+ Joi.assert(options, Joi.object().required());
13
+ Joi.assert(options.parent, Joi.object().required());
14
+
15
+ const self = this;
16
+ self.parent = options.parent;
17
+ self._client = self.parent.dispatch.getClient();
18
+ }
19
+
20
+ /**
21
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
22
+ * @description Get the return data and check for errors
23
+ * @param {object} retData Response HTTP
24
+ * @return {*}
25
+ * @private
26
+ */
27
+ _returnData(retData, def = {}) {
28
+ if (retData.status !== 200) {
29
+ return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
30
+ } else {
31
+ return _.get(retData, 'data', def);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @author CloudBrasil <abernardo.br@gmail.com>
37
+ * @description Set header with new session
38
+ * @param {string} session Session, token JWT
39
+ * @return {object} header with new session
40
+ * @private
41
+ */
42
+ _setHeader(session) {
43
+ return {
44
+ headers: {
45
+ authorization: session,
46
+ }
47
+ };
48
+ }
49
+
50
+ /**
51
+ * @author CloudBrasil <abernardo.br@gmail.com>
52
+ * @description Method to find available tasks for a user
53
+ * @param {object} params Params to get task
54
+ * @param {object} params.query Search process query
55
+ * @param {object} params.orgId Organization id (_id database)
56
+ * @param {string} session Session, token JWT
57
+ * @returns {promise} returned data from the search
58
+ * @returns {number} count the count of items searched
59
+ * @returns {array<object>} items the items returned from search
60
+ * @returns {number} page the page of the search (on pagination), zero indexed
61
+ * @returns {number} perPage how many items per page
62
+ * @public
63
+ * @example
64
+ *
65
+ * const API = require('@docbrasil/api-systemmanager');
66
+ * const api = new API();
67
+ * const params = {
68
+ * query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
69
+ * orgId: '55e4a3bd6be6b45210833fae',
70
+ * };
71
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
72
+ * const retSearch = await api.user.task.available.find(params, session);
73
+ */
74
+ async find(params, session) {
75
+ const self = this;
76
+
77
+ try {
78
+ Joi.assert(params, Joi.object().required(), 'Params to get task');
79
+ Joi.assert(params.query, Joi.object().required(), 'The query for the search');
80
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
81
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
82
+
83
+ const {query, orgId} = params;
84
+ const queryString = encodeURIComponent(JSON.stringify(query));
85
+ const apiCall = self._client
86
+ .post(`/organizations/${orgId}/users/tasks/groups/advsearch?query=${queryString}`, self._setHeader(session));
87
+
88
+ return self._returnData(await apiCall);
89
+ } catch (ex) {
90
+ throw ex;
91
+ }
92
+ }
93
+
94
+ /**
95
+ * @author CloudBrasil <abernardo.br@gmail.com>
96
+ * @description Method for a user to claim an available task
97
+ * @param {object} params Params to get task
98
+ * @param {object} params.taskId the task id to claim
99
+ * @param {object} params.orgname Organization slug (short name of the orgnization)
100
+ * @param {string} session Session, token JWT
101
+ * @returns {promise} returned data from the method call
102
+ * @returns {boolean} success true|false if the method was successful
103
+ * @public
104
+ * @example
105
+ *
106
+ * const API = require('@docbrasil/api-systemmanager');
107
+ * const api = new API();
108
+ * const params = {
109
+ * taskId: '55e4a3bd6be6b45210833f67',
110
+ * orgname: 'acme',
111
+ * };
112
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
113
+ * const success = await api.user.task.available.claim(params, session);
114
+ */
115
+ async claim(params, session) {
116
+ const self = this;
117
+
118
+ try {
119
+ Joi.assert(params, Joi.object().required(), 'Params to get task');
120
+ Joi.assert(params.taskId, Joi.object().required(), 'The task id to claim');
121
+ Joi.assert(params.orgname, Joi.string().required(), 'The slug of the organization');
122
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
123
+
124
+ const {query, orgId} = params;
125
+ const apiCall = self._client
126
+ .put(`/organizations/${orgname}/users/tasks/${taskId}/claim`, self._setHeader(session));
127
+
128
+ return self._returnData(await apiCall);
129
+ } catch (ex) {
130
+ throw ex;
131
+ }
132
+ }
133
+ }
134
+
135
+ export default TaskAvailable;
package/dist/bundle.cjs CHANGED
@@ -1600,6 +1600,180 @@ class Process {
1600
1600
  throw ex;
1601
1601
  }
1602
1602
  }
1603
+
1604
+ /**
1605
+ * @author CloudBrasil <abernardo.br@gmail.com>
1606
+ * @description Get the search info of a organization process
1607
+ * @param {object} params Params to get search info
1608
+ * @param {string} params.orgProcessId The id of an organization process (_id database);
1609
+ * @param {string} params.orgId Organization id (_id database);
1610
+ * @param {string} session Session, token JWT
1611
+ * @return {Promise} the search info result
1612
+ * @return {string} name the name of the organization process
1613
+ * @return {object} processIndexFields the list of fields to index
1614
+ * @return {object} processParticipantsGroup the permissions in this organization process
1615
+ * @return {object} stepsProperties the organization process steps properties
1616
+ * @return {string} _id the same organization id
1617
+ * @
1618
+ * @public
1619
+ * @async
1620
+ * @example
1621
+ *
1622
+ * const API = require('@docbrasil/api-systemmanager');
1623
+ * const api = new API();
1624
+ * const params = {
1625
+ * orgProcessId: '5dadd01dc4af3941d42f8c67',
1626
+ * orgId: '5edd11c46b6ce9729c2c297c',
1627
+ * }
1628
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
1629
+ * const retSearchInfo = await api.user.process.getOrgProcessSearchInfo(params, session);
1630
+ */
1631
+ async getOrgProcessSearchInfo(params, session) {
1632
+ const self = this;
1633
+
1634
+ try {
1635
+ Joi__default["default"].assert(params, Joi__default["default"].object().required());
1636
+ Joi__default["default"].assert(params.orgProcessId, Joi__default["default"].string().required());
1637
+ Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required());
1638
+ Joi__default["default"].assert(session, Joi__default["default"].string().required());
1639
+
1640
+ const {orgProcessId, orgId} = params;
1641
+ const apiCall = self._client.get(`/organizations/${orgId}/orgprocess/${orgProcessId}/search/info`, self._setHeader(session));
1642
+ return self._returnData(await apiCall);
1643
+ } catch (ex) {
1644
+ throw ex;
1645
+ }
1646
+ }
1647
+ }
1648
+
1649
+ /**
1650
+ * Class for available tasks, permission user
1651
+ * @class
1652
+ */
1653
+ class TaskAvailable {
1654
+
1655
+ constructor(options) {
1656
+ Joi__default["default"].assert(options, Joi__default["default"].object().required());
1657
+ Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
1658
+
1659
+ const self = this;
1660
+ self.parent = options.parent;
1661
+ self._client = self.parent.dispatch.getClient();
1662
+ }
1663
+
1664
+ /**
1665
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
1666
+ * @description Get the return data and check for errors
1667
+ * @param {object} retData Response HTTP
1668
+ * @return {*}
1669
+ * @private
1670
+ */
1671
+ _returnData(retData, def = {}) {
1672
+ if (retData.status !== 200) {
1673
+ return Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
1674
+ } else {
1675
+ return ___default["default"].get(retData, 'data', def);
1676
+ }
1677
+ }
1678
+
1679
+ /**
1680
+ * @author CloudBrasil <abernardo.br@gmail.com>
1681
+ * @description Set header with new session
1682
+ * @param {string} session Session, token JWT
1683
+ * @return {object} header with new session
1684
+ * @private
1685
+ */
1686
+ _setHeader(session) {
1687
+ return {
1688
+ headers: {
1689
+ authorization: session,
1690
+ }
1691
+ };
1692
+ }
1693
+
1694
+ /**
1695
+ * @author CloudBrasil <abernardo.br@gmail.com>
1696
+ * @description Method to find available tasks for a user
1697
+ * @param {object} params Params to get task
1698
+ * @param {object} params.query Search process query
1699
+ * @param {object} params.orgId Organization id (_id database)
1700
+ * @param {string} session Session, token JWT
1701
+ * @returns {promise} returned data from the search
1702
+ * @returns {number} count the count of items searched
1703
+ * @returns {array<object>} items the items returned from search
1704
+ * @returns {number} page the page of the search (on pagination), zero indexed
1705
+ * @returns {number} perPage how many items per page
1706
+ * @public
1707
+ * @example
1708
+ *
1709
+ * const API = require('@docbrasil/api-systemmanager');
1710
+ * const api = new API();
1711
+ * const params = {
1712
+ * query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
1713
+ * orgId: '55e4a3bd6be6b45210833fae',
1714
+ * };
1715
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
1716
+ * const retSearch = await api.user.task.available.find(params, session);
1717
+ */
1718
+ async find(params, session) {
1719
+ const self = this;
1720
+
1721
+ try {
1722
+ Joi__default["default"].assert(params, Joi__default["default"].object().required(), 'Params to get task');
1723
+ Joi__default["default"].assert(params.query, Joi__default["default"].object().required(), 'The query for the search');
1724
+ Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required(), 'Organization id (_id database)');
1725
+ Joi__default["default"].assert(session, Joi__default["default"].string().required(), 'Session token JWT');
1726
+
1727
+ const {query, orgId} = params;
1728
+ const queryString = encodeURIComponent(JSON.stringify(query));
1729
+ const apiCall = self._client
1730
+ .post(`/organizations/${orgId}/users/tasks/groups/advsearch?query=${queryString}`, self._setHeader(session));
1731
+
1732
+ return self._returnData(await apiCall);
1733
+ } catch (ex) {
1734
+ throw ex;
1735
+ }
1736
+ }
1737
+
1738
+ /**
1739
+ * @author CloudBrasil <abernardo.br@gmail.com>
1740
+ * @description Method for a user to claim an available task
1741
+ * @param {object} params Params to get task
1742
+ * @param {object} params.taskId the task id to claim
1743
+ * @param {object} params.orgname Organization slug (short name of the orgnization)
1744
+ * @param {string} session Session, token JWT
1745
+ * @returns {promise} returned data from the method call
1746
+ * @returns {boolean} success true|false if the method was successful
1747
+ * @public
1748
+ * @example
1749
+ *
1750
+ * const API = require('@docbrasil/api-systemmanager');
1751
+ * const api = new API();
1752
+ * const params = {
1753
+ * taskId: '55e4a3bd6be6b45210833f67',
1754
+ * orgname: 'acme',
1755
+ * };
1756
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
1757
+ * const success = await api.user.task.available.claim(params, session);
1758
+ */
1759
+ async claim(params, session) {
1760
+ const self = this;
1761
+
1762
+ try {
1763
+ Joi__default["default"].assert(params, Joi__default["default"].object().required(), 'Params to get task');
1764
+ Joi__default["default"].assert(params.taskId, Joi__default["default"].object().required(), 'The task id to claim');
1765
+ Joi__default["default"].assert(params.orgname, Joi__default["default"].string().required(), 'The slug of the organization');
1766
+ Joi__default["default"].assert(session, Joi__default["default"].string().required(), 'Session token JWT');
1767
+
1768
+ const {query, orgId} = params;
1769
+ const apiCall = self._client
1770
+ .put(`/organizations/${orgname}/users/tasks/${taskId}/claim`, self._setHeader(session));
1771
+
1772
+ return self._returnData(await apiCall);
1773
+ } catch (ex) {
1774
+ throw ex;
1775
+ }
1776
+ }
1603
1777
  }
1604
1778
 
1605
1779
  /**
@@ -1615,6 +1789,7 @@ class Task {
1615
1789
  const self = this;
1616
1790
  self.parent = options.parent;
1617
1791
  self._client = self.parent.dispatch.getClient();
1792
+ self.available = new TaskAvailable(options);
1618
1793
  }
1619
1794
 
1620
1795
  /**