@docbrasil/api-systemmanager 1.0.120 → 1.0.121

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.
@@ -0,0 +1,113 @@
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+
5
+ /**
6
+ * Class for user registration in a user
7
+ * @class
8
+ */
9
+ class Help {
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 Augusto Pissarra <abernardo.br@gmail.com>
52
+ * @description get heps topics
53
+ * @param {string} session JWT token
54
+ * @public
55
+ * @async
56
+ * @example
57
+ *
58
+ * const API = require('@docbrasil/api-systemmanager');
59
+ * const api = new API();
60
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
61
+ * await api.user.help.getTopics(session);
62
+ */
63
+ async getTopics(session) {
64
+ const self = this;
65
+
66
+ try {
67
+ Joi.assert(session, Joi.string().required(), 'SM session (JWT) to call API');
68
+
69
+ const apiCall = self._client.get('/help/topics', self._setHeader(session));
70
+ return self._returnData(await apiCall);
71
+ } catch (ex) {
72
+ throw ex;
73
+ }
74
+ }
75
+
76
+ /**
77
+ * @author CloudBrasil <abernardo.br@gmail.com>
78
+ * @description Method to find helps from a topic
79
+ * @param {object} params Params to get helps from topic
80
+ * @param {object} params.id Topic id (_id database)
81
+ * @param {string} session Session, token JWT
82
+ * @returns {promise}
83
+ * @public
84
+ * @example
85
+ *
86
+ * const API = require('@docbrasil/api-systemmanager');
87
+ * const api = new API();
88
+ * const params = {
89
+ * id: '5dadd01dc4af3941d42f8c5c'
90
+ * };
91
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
92
+ * await api.user.help.get(params, session);
93
+ */
94
+ async get(params, session) {
95
+ const self = this;
96
+
97
+ try {
98
+ Joi.assert(params, Joi.object().required(), 'Params to helps from a topic');
99
+ Joi.assert(params.id, Joi.string().required(), 'Topic id (_id database)');
100
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
101
+
102
+ const {id} = params;
103
+ const apiCall = self._client.get(`/help/topic/${id}`, self._setHeader(session));
104
+
105
+ return self._returnData(await apiCall);
106
+ } catch (ex) {
107
+ throw ex;
108
+ }
109
+ }
110
+
111
+ }
112
+
113
+ export default Help;
package/doc/api.md CHANGED
@@ -49,6 +49,9 @@
49
49
  <dt><a href="#Documents">Documents</a></dt>
50
50
  <dd><p>Class for documents, permission user</p>
51
51
  </dd>
52
+ <dt><a href="#Help">Help</a></dt>
53
+ <dd><p>Class for user registration in a user</p>
54
+ </dd>
52
55
  <dt><a href="#Users">Users</a></dt>
53
56
  <dd><p>API request, user permission level</p>
54
57
  </dd>
@@ -1681,6 +1684,62 @@ const params = {
1681
1684
  const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
1682
1685
  const retSearch = await api.user.document.searchDocuments(params, session);
1683
1686
  ```
1687
+ <a name="Help"></a>
1688
+
1689
+ ## Help
1690
+ Class for user registration in a user
1691
+
1692
+ **Kind**: global class
1693
+
1694
+ * [Help](#Help)
1695
+ * [.getTopics(session)](#Help+getTopics)
1696
+ * [.get(params, session)](#Help+get) ⇒ <code>promise</code>
1697
+
1698
+ <a name="Help+getTopics"></a>
1699
+
1700
+ ### help.getTopics(session)
1701
+ get heps topics
1702
+
1703
+ **Kind**: instance method of [<code>Help</code>](#Help)
1704
+ **Access**: public
1705
+ **Author**: Augusto Pissarra <abernardo.br@gmail.com>
1706
+
1707
+ | Param | Type | Description |
1708
+ | --- | --- | --- |
1709
+ | session | <code>string</code> | JWT token |
1710
+
1711
+ **Example**
1712
+ ```js
1713
+ const API = require('@docbrasil/api-systemmanager');
1714
+ const api = new API();
1715
+ const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
1716
+ await api.user.help.getTopics(session);
1717
+ ```
1718
+ <a name="Help+get"></a>
1719
+
1720
+ ### help.get(params, session) ⇒ <code>promise</code>
1721
+ Method to find helps from a topic
1722
+
1723
+ **Kind**: instance method of [<code>Help</code>](#Help)
1724
+ **Access**: public
1725
+ **Author**: CloudBrasil <abernardo.br@gmail.com>
1726
+
1727
+ | Param | Type | Description |
1728
+ | --- | --- | --- |
1729
+ | params | <code>object</code> | Params to get helps from topic |
1730
+ | params.id | <code>object</code> | Topic id (_id database) |
1731
+ | session | <code>string</code> | Session, token JWT |
1732
+
1733
+ **Example**
1734
+ ```js
1735
+ const API = require('@docbrasil/api-systemmanager');
1736
+ const api = new API();
1737
+ const params = {
1738
+ id: '5dadd01dc4af3941d42f8c5c'
1739
+ };
1740
+ const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
1741
+ await api.user.help.get(params, session);
1742
+ ```
1684
1743
  <a name="Users"></a>
1685
1744
 
1686
1745
  ## Users
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docbrasil/api-systemmanager",
3
3
  "description": "Module API System Manager",
4
- "version": "1.0.120",
4
+ "version": "1.0.121",
5
5
  "scripts": {
6
6
  "htmldoc": "rm -rf docs && jsdoc api/** -d docs -t ./node_modules/better-docs",
7
7
  "doc": "rm -rf doc && mkdir doc && jsdoc2md api/**/* api/* > doc/api.md",