@docbrasil/api-systemmanager 1.0.119 → 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/dist/bundle.cjs CHANGED
@@ -9488,7 +9488,7 @@ class Register {
9488
9488
  * Class for user registration in a user
9489
9489
  * @class
9490
9490
  */
9491
- class Notification$1 {
9491
+ class Notification {
9492
9492
 
9493
9493
  constructor(options) {
9494
9494
  Joi__default["default"].assert(options, Joi__default["default"].object().required());
@@ -9704,7 +9704,78 @@ class Notification$1 {
9704
9704
  }
9705
9705
  }
9706
9706
 
9707
- var Updates = Notification;
9707
+ /**
9708
+ * Class for user registration in a user
9709
+ * @class
9710
+ */
9711
+ class Updates {
9712
+
9713
+ constructor(options) {
9714
+ Joi__default["default"].assert(options, Joi__default["default"].object().required());
9715
+ Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
9716
+
9717
+ const self = this;
9718
+ self.parent = options.parent;
9719
+ self._client = self.parent.dispatch.getClient();
9720
+ }
9721
+
9722
+ /**
9723
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
9724
+ * @description Get the return data and check for errors
9725
+ * @param {object} retData Response HTTP
9726
+ * @return {*}
9727
+ * @private
9728
+ */
9729
+ _returnData(retData, def = {}) {
9730
+ if (retData.status !== 200) {
9731
+ return Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
9732
+ } else {
9733
+ return ___default["default"].get(retData, 'data', def);
9734
+ }
9735
+ }
9736
+
9737
+ /**
9738
+ * @author CloudBrasil <abernardo.br@gmail.com>
9739
+ * @description Set header with new session
9740
+ * @param {string} session Session, token JWT
9741
+ * @return {object} header with new session
9742
+ * @private
9743
+ */
9744
+ _setHeader(session) {
9745
+ return {
9746
+ headers: {
9747
+ authorization: session,
9748
+ }
9749
+ };
9750
+ }
9751
+
9752
+ /**
9753
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
9754
+ * @description get updates
9755
+ * @param {string} session JWT token
9756
+ * @public
9757
+ * @async
9758
+ * @example
9759
+ *
9760
+ * const API = require('@docbrasil/api-systemmanager');
9761
+ * const api = new API();
9762
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
9763
+ * await api.user.updates.get(session);
9764
+ */
9765
+ async get(session) {
9766
+ const self = this;
9767
+
9768
+ try {
9769
+ Joi__default["default"].assert(session, Joi__default["default"].string().required(), 'SM session (JWT) to call API');
9770
+
9771
+ const apiCall = self._client.get('/updates', self._setHeader(session));
9772
+ return self._returnData(await apiCall);
9773
+ } catch (ex) {
9774
+ throw ex;
9775
+ }
9776
+ }
9777
+
9778
+ }
9708
9779
 
9709
9780
  /**
9710
9781
  * Class for user datasource access, to be used with when creating new documents
@@ -9867,7 +9938,7 @@ class Users {
9867
9938
  self.task = new Task(options);
9868
9939
  self.user = self.profile = new User(options);
9869
9940
  self.register = new Register(options);
9870
- self.notification = new Notification$1(options);
9941
+ self.notification = new Notification(options);
9871
9942
  self.updates = new Updates(options);
9872
9943
  }
9873
9944
  }