@docbrasil/api-systemmanager 1.1.23 → 1.1.24

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.
Files changed (78) hide show
  1. package/api/user/dashboard.js +150 -0
  2. package/api/user/index.js +2 -0
  3. package/dist/bundle.cjs +5 -2
  4. package/dist/bundle.mjs +1 -1
  5. package/doc/api.md +59 -0
  6. package/docs/Admin.html +1 -1
  7. package/docs/AdminDocuments.html +1 -1
  8. package/docs/AdminForm.html +1 -1
  9. package/docs/AdminLists.html +1 -1
  10. package/docs/AdminMessage.html +1 -1
  11. package/docs/AdminNotification.html +1 -1
  12. package/docs/AdminPlugin.html +1 -1
  13. package/docs/AdminPolicy.html +1 -1
  14. package/docs/AdminProcesses.html +1 -1
  15. package/docs/AdminTask.html +1 -1
  16. package/docs/AdminUser.html +1 -1
  17. package/docs/Application.html +1 -1
  18. package/docs/Chart.html +528 -0
  19. package/docs/Dashboard.html +349 -0
  20. package/docs/Datasource.html +1 -1
  21. package/docs/Dispatch.html +1 -1
  22. package/docs/Documents.html +1 -1
  23. package/docs/External.html +1 -1
  24. package/docs/GeoLocation.html +1 -1
  25. package/docs/Help.html +1 -1
  26. package/docs/Login.html +1 -1
  27. package/docs/MyTasks.html +1 -1
  28. package/docs/Notification.html +1 -1
  29. package/docs/Organization.html +1 -1
  30. package/docs/Page.html +1 -1
  31. package/docs/Process.html +1 -1
  32. package/docs/Register.html +1 -1
  33. package/docs/Session.html +1 -1
  34. package/docs/Settings.html +1 -1
  35. package/docs/Task.html +1 -1
  36. package/docs/TaskAvailable.html +1 -1
  37. package/docs/Updates.html +1 -1
  38. package/docs/User.html +1 -1
  39. package/docs/Users.html +2 -2
  40. package/docs/admin_doctypes.js.html +1 -1
  41. package/docs/admin_document.js.html +1 -1
  42. package/docs/admin_form.js.html +1 -1
  43. package/docs/admin_index.js.html +1 -1
  44. package/docs/admin_list.js.html +1 -1
  45. package/docs/admin_message.js.html +1 -1
  46. package/docs/admin_notification.js.html +1 -1
  47. package/docs/admin_organization.js.html +1 -1
  48. package/docs/admin_plugin.js.html +1 -1
  49. package/docs/admin_policy.js.html +1 -1
  50. package/docs/admin_processes.js.html +1 -1
  51. package/docs/admin_task.js.html +1 -1
  52. package/docs/admin_user.js.html +1 -1
  53. package/docs/dispatch.js.html +1 -1
  54. package/docs/external.js.html +1 -1
  55. package/docs/general_geoLocation.js.html +1 -1
  56. package/docs/general_index.js.html +1 -1
  57. package/docs/index.html +1 -1
  58. package/docs/login.js.html +1 -1
  59. package/docs/session.js.html +1 -1
  60. package/docs/user_application.js.html +1 -1
  61. package/docs/user_dashboard.js.html +267 -0
  62. package/docs/user_datasource.js.html +1 -1
  63. package/docs/user_document.js.html +1 -1
  64. package/docs/user_help.js.html +1 -1
  65. package/docs/user_index.js.html +3 -1
  66. package/docs/user_my_tasks.js.html +1 -1
  67. package/docs/user_notification.js.html +1 -1
  68. package/docs/user_organization.js.html +1 -1
  69. package/docs/user_page.js.html +1 -1
  70. package/docs/user_process.js.html +1 -1
  71. package/docs/user_register.js.html +1 -1
  72. package/docs/user_settings.js.html +1 -1
  73. package/docs/user_task.js.html +1 -1
  74. package/docs/user_task_available.js.html +1 -1
  75. package/docs/user_updates.js.html +1 -1
  76. package/docs/user_user.js.html +1 -1
  77. package/docs/utils_promises.js.html +1 -1
  78. package/package.json +1 -1
@@ -0,0 +1,150 @@
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+
5
+ /**
6
+ * Class user access to charts
7
+ * @class
8
+ */
9
+ class Chart {
10
+ constructor(options) {
11
+ Joi.assert(options, Joi.object().required());
12
+ Joi.assert(options.parent, Joi.object().required());
13
+
14
+ const self = this;
15
+ self.parent = options.parent;
16
+ self._client = self.parent.dispatch.getClient();
17
+ }
18
+
19
+ /**
20
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
21
+ * @description Get the return data and check for errors
22
+ * @param {object} retData Response HTTP
23
+ * @return {*}
24
+ * @private
25
+ */
26
+ _returnData(retData, def = {}) {
27
+ if (retData.status !== 200) {
28
+ return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
29
+ } else {
30
+ return _.get(retData, 'data', def);
31
+ }
32
+ }
33
+
34
+ /**
35
+ * @author Myndware <augusto.pissarra@myndware.com>
36
+ * @description Set header with new session
37
+ * @param {string} session Session, token JWT
38
+ * @return {object} header with new session
39
+ * @private
40
+ */
41
+ _setHeader(session) {
42
+ return {
43
+ headers: {
44
+ authorization: session,
45
+ }
46
+ };
47
+ }
48
+
49
+ /**
50
+ * @author Myndware <augusto.pissarra@myndware.com>
51
+ * @description Get the data for a chart
52
+ * @param {object} params Params to get helps from topic
53
+ * @param {object} params.type Type of the chart data
54
+ * @param {object} params.query The query if any
55
+ * @param {string} session Session, token JWT
56
+ * @returns {promise}
57
+ * @public
58
+ * @example
59
+ *
60
+ * const API = require('@docbrasil/api-systemmanager');
61
+ * const api = new API();
62
+ * const params = {
63
+ * type: 'heatmap_data'
64
+ * };
65
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
66
+ * await api.user.dashboard.chart.getData(params, session);
67
+ */
68
+ async getData(params, session) {
69
+ const self = this;
70
+
71
+ try {
72
+ Joi.assert(params, Joi.object().required(), 'Params to helps from a topic');
73
+ Joi.assert(params.type, Joi.string().required(), 'Type of graph');
74
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
75
+
76
+ const { type, query = {} } = params;
77
+ const apiCall = self._client.post(`/organizations/dashboard/chart/data/${type}`, query, self._setHeader(session));
78
+
79
+ return self._returnData(await apiCall);
80
+ } catch (ex) {
81
+ throw ex;
82
+ }
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Class user access to dashboards
88
+ * @class
89
+ */
90
+ class Dashboard {
91
+
92
+ constructor(options) {
93
+ Joi.assert(options, Joi.object().required());
94
+ Joi.assert(options.parent, Joi.object().required());
95
+
96
+ const self = this;
97
+ self.parent = options.parent;
98
+ self._client = self.parent.dispatch.getClient();
99
+ self._chart = new Chart(options);
100
+ }
101
+
102
+ /**
103
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
104
+ * @description Get the return data and check for errors
105
+ * @param {object} retData Response HTTP
106
+ * @return {*}
107
+ * @private
108
+ */
109
+ _returnData(retData, def = {}) {
110
+ if (retData.status !== 200) {
111
+ return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
112
+ } else {
113
+ return _.get(retData, 'data', def);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * @author Myndware <augusto.pissarra@myndware.com>
119
+ * @description Set header with new session
120
+ * @param {string} session Session, token JWT
121
+ * @return {object} header with new session
122
+ * @private
123
+ */
124
+ _setHeader(session) {
125
+ return {
126
+ headers: {
127
+ authorization: session,
128
+ }
129
+ };
130
+ }
131
+
132
+ /**
133
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
134
+ * @description return the chart
135
+ * @public
136
+ * @async
137
+ * @example
138
+ *
139
+ * const API = require('@docbrasil/api-systemmanager');
140
+ * const api = new API();
141
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
142
+ * await api.user.help.getTopics({}, session);
143
+ */
144
+ get chart() {
145
+ const self = this;
146
+ return self._chart;
147
+ }
148
+ }
149
+
150
+ export default Help;
package/api/user/index.js CHANGED
@@ -13,6 +13,7 @@ import Help from './help.js';
13
13
  import Datasource from './datasource.js';
14
14
  import Application from './application.js';
15
15
  import Settings from './settings.js';
16
+ import Dashboard from './dashboard.js';
16
17
 
17
18
  /**
18
19
  * @class API request, user permission level
@@ -41,6 +42,7 @@ class Users {
41
42
  self.updates = new Updates(options);
42
43
  self.help = new Help(options);
43
44
  self.application = new Application(options);
45
+ self.dashboard = new Dashboard(options);
44
46
  }
45
47
  }
46
48
 
package/dist/bundle.cjs CHANGED
@@ -10446,7 +10446,7 @@ class Updates {
10446
10446
  * Class for user registration in a user
10447
10447
  * @class
10448
10448
  */
10449
- class Help {
10449
+ class Help$1 {
10450
10450
 
10451
10451
  constructor(options) {
10452
10452
  Joi__default["default"].assert(options, Joi__default["default"].object().required());
@@ -11002,6 +11002,8 @@ class Settings {
11002
11002
  }
11003
11003
  }
11004
11004
 
11005
+ var Dashboard = Help;
11006
+
11005
11007
  /**
11006
11008
  * @class API request, user permission level
11007
11009
  */
@@ -11027,8 +11029,9 @@ class Users {
11027
11029
  self.register = new Register(options);
11028
11030
  self.notification = new Notification(options);
11029
11031
  self.updates = new Updates(options);
11030
- self.help = new Help(options);
11032
+ self.help = new Help$1(options);
11031
11033
  self.application = new Application(options);
11034
+ self.dashboard = new Dashboard(options);
11032
11035
  }
11033
11036
  }
11034
11037