@docbrasil/api-systemmanager 1.0.107 → 1.0.109

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 (73) hide show
  1. package/.github/workflows/static.yml +43 -0
  2. package/api/external.js +41 -0
  3. package/dist/bundle.cjs +41 -0
  4. package/dist/bundle.mjs +1 -1
  5. package/doc/api.md +382 -0
  6. package/docs/Admin.html +336 -0
  7. package/docs/AdminDocuments.html +2235 -0
  8. package/docs/AdminForm.html +934 -0
  9. package/docs/AdminLists.html +895 -0
  10. package/docs/AdminMessage.html +1490 -0
  11. package/docs/AdminNotification.html +1636 -0
  12. package/docs/AdminPlugin.html +696 -0
  13. package/docs/AdminPolicy.html +451 -0
  14. package/docs/AdminProcesses.html +692 -0
  15. package/docs/AdminTask.html +740 -0
  16. package/docs/AdminUser.html +1203 -0
  17. package/docs/Datasource.html +660 -0
  18. package/docs/Dispatch.html +624 -0
  19. package/docs/Documents.html +4875 -0
  20. package/docs/External.html +1497 -0
  21. package/docs/GeoLocation.html +503 -0
  22. package/docs/Login.html +1839 -0
  23. package/docs/Notification.html +625 -0
  24. package/docs/Organization.html +2767 -0
  25. package/docs/Process.html +1598 -0
  26. package/docs/Register.html +1604 -0
  27. package/docs/Session.html +482 -0
  28. package/docs/Task.html +1394 -0
  29. package/docs/TaskAvailable.html +893 -0
  30. package/docs/User.html +2002 -0
  31. package/docs/Users.html +569 -0
  32. package/docs/admin_doctypes.js.html +193 -0
  33. package/docs/admin_document.js.html +449 -0
  34. package/docs/admin_form.js.html +268 -0
  35. package/docs/admin_index.js.html +163 -0
  36. package/docs/admin_list.js.html +250 -0
  37. package/docs/admin_message.js.html +311 -0
  38. package/docs/admin_notification.js.html +350 -0
  39. package/docs/admin_organization.js.html +241 -0
  40. package/docs/admin_plugin.js.html +233 -0
  41. package/docs/admin_policy.js.html +195 -0
  42. package/docs/admin_processes.js.html +487 -0
  43. package/docs/admin_task.js.html +242 -0
  44. package/docs/admin_user.js.html +302 -0
  45. package/docs/dispatch.js.html +218 -0
  46. package/docs/external.js.html +333 -0
  47. package/docs/general_geoLocation.js.html +205 -0
  48. package/docs/general_index.js.html +140 -0
  49. package/docs/index.html +129 -0
  50. package/docs/login.js.html +384 -0
  51. package/docs/scripts/app.min.js +1 -0
  52. package/docs/scripts/linenumber.js +26 -0
  53. package/docs/scripts/search.js +39 -0
  54. package/docs/session.js.html +202 -0
  55. package/docs/styles/app.min.css +1 -0
  56. package/docs/styles/iframe.css +13 -0
  57. package/docs/styles/prettify-jsdoc.css +111 -0
  58. package/docs/styles/prettify-tomorrow.css +132 -0
  59. package/docs/styles/reset.css +44 -0
  60. package/docs/user_datasource.js.html +261 -0
  61. package/docs/user_document.js.html +847 -0
  62. package/docs/user_index.js.html +156 -0
  63. package/docs/user_notification.js.html +218 -0
  64. package/docs/user_organization.js.html +347 -0
  65. package/docs/user_process.js.html +352 -0
  66. package/docs/user_register.js.html +322 -0
  67. package/docs/user_task.js.html +319 -0
  68. package/docs/user_task_available.js.html +252 -0
  69. package/docs/user_user.js.html +404 -0
  70. package/docs/utils_promises.js.html +235 -0
  71. package/package.json +7 -4
  72. package/readme.md +7 -8
  73. package/doc.md +0 -653
@@ -0,0 +1,311 @@
1
+
2
+
3
+ <!DOCTYPE html>
4
+ <html lang="en">
5
+
6
+ <head>
7
+
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+ <title> admin/message.js</title>
11
+
12
+ <script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
13
+ <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
14
+ <script src="./build/entry.js"></script>
15
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
16
+ <!--[if lt IE 9]>
17
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
18
+ <![endif]-->
19
+ <link href="https://fonts.googleapis.com/css?family=Roboto:100,400,700|Inconsolata,700" rel="stylesheet">
20
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
21
+ <link type="text/css" rel="stylesheet" href="https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css">
22
+ <link type="text/css" rel="stylesheet" href="styles/app.min.css">
23
+ <link type="text/css" rel="stylesheet" href="styles/iframe.css">
24
+ <link type="text/css" rel="stylesheet" href="">
25
+ <script async defer src="https://buttons.github.io/buttons.js"></script>
26
+
27
+
28
+ </head>
29
+
30
+
31
+
32
+ <body class="layout small-header">
33
+ <div id="stickyNavbarOverlay"></div>
34
+
35
+
36
+ <div class="top-nav">
37
+ <div class="inner">
38
+ <a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
39
+ <span aria-hidden="true"></span>
40
+ <span aria-hidden="true"></span>
41
+ <span aria-hidden="true"></span>
42
+ </a>
43
+ <div class="logo">
44
+
45
+
46
+ </div>
47
+ <div class="menu">
48
+
49
+ <div class="navigation">
50
+ <a
51
+ href="index.html"
52
+ class="link"
53
+ >
54
+ Documentation
55
+ </a>
56
+
57
+
58
+
59
+ </div>
60
+ </div>
61
+ </div>
62
+ </div>
63
+ <div id="main">
64
+ <div
65
+ class="sidebar "
66
+ id="sidebarNav"
67
+ >
68
+
69
+ <nav>
70
+
71
+ <h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Classes</h3><ul><li><a href="Admin.html">Admin</a></li><li><a href="AdminDocuments.html">AdminDocuments</a></li><li><a href="AdminForm.html">AdminForm</a></li><li><a href="AdminLists.html">AdminLists</a></li><li><a href="AdminMessage.html">AdminMessage</a></li><li><a href="AdminNotification.html">AdminNotification</a></li><li><a href="AdminPlugin.html">AdminPlugin</a></li><li><a href="AdminPolicy.html">AdminPolicy</a></li><li><a href="AdminProcesses.html">AdminProcesses</a></li><li><a href="AdminTask.html">AdminTask</a></li><li><a href="AdminUser.html">AdminUser</a></li><li><a href="Datasource.html">Datasource</a></li><li><a href="Dispatch.html">Dispatch</a></li><li><a href="Documents.html">Documents</a></li><li><a href="External.html">External</a></li><li><a href="GeoLocation.html">GeoLocation</a></li><li><a href="Login.html">Login</a></li><li><a href="Notification.html">Notification</a></li><li><a href="Organization.html">Organization</a></li><li><a href="Process.html">Process</a></li><li><a href="Register.html">Register</a></li><li><a href="Session.html">Session</a></li><li><a href="Task.html">Task</a></li><li><a href="TaskAvailable.html">TaskAvailable</a></li><li><a href="User.html">User</a></li><li><a href="Users.html">Users</a></li></ul></div>
72
+
73
+ </nav>
74
+ </div>
75
+ <div class="core" id="main-content-wrapper">
76
+ <div class="content">
77
+ <header class="page-title">
78
+ <p>Source</p>
79
+ <h1>admin/message.js</h1>
80
+ </header>
81
+
82
+
83
+
84
+
85
+
86
+ <section>
87
+ <article>
88
+ <pre class="prettyprint source linenums"><code>import _ from 'lodash';
89
+ import Boom from '@hapi/boom';
90
+ import Joi from 'joi';
91
+
92
+ /**
93
+ * Admin Class for user, permission admin
94
+ * @class
95
+ */
96
+ class AdminMessage {
97
+
98
+ constructor(options) {
99
+ Joi.assert(options, Joi.object().required());
100
+ Joi.assert(options.parent, Joi.object().required());
101
+
102
+ const self = this;
103
+ self.parent = options.parent;
104
+ self.client = self.parent.dispatch.getClient();
105
+ }
106
+
107
+ /**
108
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
109
+ * @description Get the return data and check for errors
110
+ * @param {object} retData Response HTTP
111
+ * @return {*}
112
+ * @private
113
+ */
114
+ _returnData(retData, def = {}) {
115
+ if (retData.status !== 200) {
116
+ return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
117
+ } else {
118
+ return _.get(retData, 'data', def);
119
+ }
120
+ }
121
+
122
+ /**
123
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
124
+ * @description Set header with new session
125
+ * @param {string} session Session, token JWT
126
+ * @return {object} header with new session
127
+ * @private
128
+ */
129
+ _setHeader(session) {
130
+ return {
131
+ headers: {
132
+ authorization: session,
133
+ }
134
+ };
135
+ }
136
+
137
+ /**
138
+ * @description Pagination SMS texts
139
+ * @param {!object} params - Params to pagintion SMS
140
+ * @param {!string} params.message - Message to pagination
141
+ * @param {!number} params.limitSize=130 - Limit of the start pagination
142
+ * @param {!number} params.continueText=continua... - Text to continue other SMS
143
+ */
144
+ _paginationOfTheSMS(params) {
145
+ const self = this;
146
+ try {
147
+ Joi.assert(params, Joi.object().required(), 'Params to paginate SMS');
148
+ Joi.assert(params.message, Joi.string(), 'Message to pagination');
149
+ Joi.assert(params.limitSize, Joi.number(), 'Limit of the start pagination');
150
+ Joi.assert(params.continueText, Joi.string(), 'Text to continue other SMS');
151
+
152
+ const defaultSize = 130;
153
+ const defaultContinue = 'continua...';
154
+ const { message, limitSize = defaultSize, continueText = defaultContinue } = params;
155
+
156
+ const size = limitSize - continueText.length;
157
+ const regex = new RegExp(`.{1,${size}}`, 'g');
158
+ const smsData = message.match(regex).map(item => item.trim());
159
+ const smsDataWithContinue = smsData.map((message, index, arr) => {
160
+ return index !== (arr.length - 1)
161
+ ? `${message} ${continueText}`
162
+ : message;
163
+ });
164
+
165
+ return smsDataWithContinue;
166
+
167
+ } catch (ex) {
168
+ throw ex;
169
+ }
170
+ }
171
+
172
+ /**
173
+ * @description Validation struct to send email
174
+ * @param {!object} params - Params to send email
175
+ * @param {!string} params.subject - Subject of the email
176
+ * @param {!string} params.message - Body of the email
177
+ * @param {!string} params.to - Destination email
178
+ * @param {?string} params.from - Source email
179
+ */
180
+ _validItemToSendEmail(params) {
181
+ try {
182
+ Joi.assert(params, Joi.object().required(), 'Params to send email');
183
+ Joi.assert(params.subject, Joi.string().required(), 'Subject of the email');
184
+ Joi.assert(params.message, Joi.string().required(), 'Body of the email');
185
+ Joi.assert(params.to, Joi.string().required(), 'Destination email');
186
+ Joi.assert(params.from, Joi.string(), 'Source email');
187
+
188
+ return true;
189
+ } catch (ex) {
190
+ throw ex;
191
+ }
192
+ }
193
+
194
+ /**
195
+ * @description Send an SMS message
196
+ * @param {!object} params - Params to send SMS
197
+ * @param {!string} params.apiKey - Organization API key
198
+ * @param {!string} params.message - The text message to send
199
+ * @param {!string} params.recipient - The telephone number without with only numbers
200
+ * @param {?number} params.limitSize=130 - Size limit to send SMS
201
+ * @return {Promise&lt;{}>}
202
+ */
203
+ async sendSMS(params) {
204
+ const self = this;
205
+ try {
206
+ Joi.assert(params, Joi.object().required(), 'Params to send SMS');
207
+ Joi.assert(params.apiKey, Joi.string().required(), 'Organization API key');
208
+ Joi.assert(params.message, Joi.string().required(), 'The text message to send');
209
+ Joi.assert(params.recipient, Joi.string().required(), 'The telephone number without with only numbers');
210
+ Joi.assert(params.limitSize, Joi.number(), 'Size limit to send SMS');
211
+
212
+ const defaultSize = 130;
213
+ const { apiKey, message, recipient, limitSize = defaultSize } = params;
214
+
215
+ const paramsOfThePagination = { message, limitSize };
216
+ const smsData = self._paginationOfTheSMS(paramsOfThePagination);
217
+
218
+ for await (const smsText of smsData) {
219
+ const payload = { apiKey, data: { message: smsText }, recipient };
220
+ await self.client.post('/sms/send', payload);
221
+ }
222
+
223
+ return { success: true, send: smsData.length };
224
+
225
+ } catch (ex) {
226
+ throw ex;
227
+ }
228
+ }
229
+
230
+ /**
231
+ * @description Send email, array with email list or send one email
232
+ * @param {!object} params - Params to send email
233
+ * @param {!string} params.subject - Subject of the email
234
+ * @param {!string} params.message - Body of the email
235
+ * @param {!string} params.to - Destination email
236
+ * @param {?string} params.from - Source email
237
+ * @param {string} session - Session, token JWT
238
+ * @return {Promise&lt;{success: boolean, sent: object[]}>} - Success and email sent
239
+ * @example
240
+ *
241
+ * const API = require('@docbrasil/api-systemmanager');
242
+ * const api = new API();
243
+ * const params = {
244
+ * subject: 'Test email',
245
+ * message: '&lt;h1>Hi!&lt;/h1>',
246
+ * to: 'destination@gmail.com'
247
+ * };
248
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
249
+ * await api.admin.message.sendEmail(params, session);
250
+ */
251
+ async sendEmail(params, session) {
252
+ const self = this;
253
+
254
+ try {
255
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
256
+
257
+ let emailList = [];
258
+ const emailSent = [];
259
+
260
+ if (Array.isArray(params)) {
261
+ params.forEach(element => self._validItemToSendEmail(element));
262
+ emailList = [...params];
263
+ } else {
264
+ self._validItemToSendEmail(params);
265
+ emailList = [params];
266
+ }
267
+
268
+ for await (const email of emailList) {
269
+ await self.client.post('/admin/email', email, self._setHeader(session));
270
+ emailSent.push(email);
271
+ }
272
+
273
+ return { success: true, sent: emailSent };
274
+
275
+ } catch (ex) {
276
+ throw ex;
277
+ }
278
+ }
279
+ }
280
+
281
+ export default AdminMessage;
282
+ </code></pre>
283
+ </article>
284
+ </section>
285
+
286
+
287
+
288
+
289
+ </div>
290
+
291
+ <footer class="footer">
292
+ <div class="content has-text-centered">
293
+ <p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a></p>
294
+ <p class="sidebar-created-by">
295
+ <a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
296
+ <a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
297
+ </p>
298
+ </div>
299
+ </footer>
300
+
301
+ </div>
302
+ <div id="side-nav" class="side-nav">
303
+ </div>
304
+ </div>
305
+ <script src="scripts/app.min.js"></script>
306
+ <script>PR.prettyPrint();</script>
307
+ <script src="scripts/linenumber.js"> </script>
308
+
309
+
310
+ </body>
311
+ </html>
@@ -0,0 +1,350 @@
1
+
2
+
3
+ <!DOCTYPE html>
4
+ <html lang="en">
5
+
6
+ <head>
7
+
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+ <title> admin/notification.js</title>
11
+
12
+ <script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
13
+ <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
14
+ <script src="./build/entry.js"></script>
15
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
16
+ <!--[if lt IE 9]>
17
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
18
+ <![endif]-->
19
+ <link href="https://fonts.googleapis.com/css?family=Roboto:100,400,700|Inconsolata,700" rel="stylesheet">
20
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
21
+ <link type="text/css" rel="stylesheet" href="https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css">
22
+ <link type="text/css" rel="stylesheet" href="styles/app.min.css">
23
+ <link type="text/css" rel="stylesheet" href="styles/iframe.css">
24
+ <link type="text/css" rel="stylesheet" href="">
25
+ <script async defer src="https://buttons.github.io/buttons.js"></script>
26
+
27
+
28
+ </head>
29
+
30
+
31
+
32
+ <body class="layout small-header">
33
+ <div id="stickyNavbarOverlay"></div>
34
+
35
+
36
+ <div class="top-nav">
37
+ <div class="inner">
38
+ <a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
39
+ <span aria-hidden="true"></span>
40
+ <span aria-hidden="true"></span>
41
+ <span aria-hidden="true"></span>
42
+ </a>
43
+ <div class="logo">
44
+
45
+
46
+ </div>
47
+ <div class="menu">
48
+
49
+ <div class="navigation">
50
+ <a
51
+ href="index.html"
52
+ class="link"
53
+ >
54
+ Documentation
55
+ </a>
56
+
57
+
58
+
59
+ </div>
60
+ </div>
61
+ </div>
62
+ </div>
63
+ <div id="main">
64
+ <div
65
+ class="sidebar "
66
+ id="sidebarNav"
67
+ >
68
+
69
+ <nav>
70
+
71
+ <h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Classes</h3><ul><li><a href="Admin.html">Admin</a></li><li><a href="AdminDocuments.html">AdminDocuments</a></li><li><a href="AdminForm.html">AdminForm</a></li><li><a href="AdminLists.html">AdminLists</a></li><li><a href="AdminMessage.html">AdminMessage</a></li><li><a href="AdminNotification.html">AdminNotification</a></li><li><a href="AdminPlugin.html">AdminPlugin</a></li><li><a href="AdminPolicy.html">AdminPolicy</a></li><li><a href="AdminProcesses.html">AdminProcesses</a></li><li><a href="AdminTask.html">AdminTask</a></li><li><a href="AdminUser.html">AdminUser</a></li><li><a href="Datasource.html">Datasource</a></li><li><a href="Dispatch.html">Dispatch</a></li><li><a href="Documents.html">Documents</a></li><li><a href="External.html">External</a></li><li><a href="GeoLocation.html">GeoLocation</a></li><li><a href="Login.html">Login</a></li><li><a href="Notification.html">Notification</a></li><li><a href="Organization.html">Organization</a></li><li><a href="Process.html">Process</a></li><li><a href="Register.html">Register</a></li><li><a href="Session.html">Session</a></li><li><a href="Task.html">Task</a></li><li><a href="TaskAvailable.html">TaskAvailable</a></li><li><a href="User.html">User</a></li><li><a href="Users.html">Users</a></li></ul></div>
72
+
73
+ </nav>
74
+ </div>
75
+ <div class="core" id="main-content-wrapper">
76
+ <div class="content">
77
+ <header class="page-title">
78
+ <p>Source</p>
79
+ <h1>admin/notification.js</h1>
80
+ </header>
81
+
82
+
83
+
84
+
85
+
86
+ <section>
87
+ <article>
88
+ <pre class="prettyprint source linenums"><code>import _ from 'lodash';
89
+ import Boom from '@hapi/boom';
90
+ import Joi from 'joi';
91
+
92
+ /**
93
+ * Admin Class for notification, permission admin
94
+ * @class
95
+ */
96
+ class AdminNotification {
97
+
98
+ constructor(options) {
99
+ Joi.assert(options, Joi.object().required());
100
+ Joi.assert(options.parent, Joi.object().required());
101
+
102
+ const self = this;
103
+ self.parent = options.parent;
104
+ self.client = self.parent.dispatch.getClient();
105
+ }
106
+
107
+ /**
108
+ * @author Augusto Pissarra &lt;abernardo.br@gmail.com>
109
+ * @description Get the return data and check for errors
110
+ * @param {object} retData Response HTTP
111
+ * @return {*}
112
+ * @private
113
+ */
114
+ _returnData(retData, def = {}) {
115
+ if (retData.status !== 200) {
116
+ return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
117
+ } else {
118
+ return _.get(retData, 'data', def);
119
+ }
120
+ }
121
+
122
+ /**
123
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
124
+ * @description Set header with new session
125
+ * @param {string} session Session, token JWT
126
+ * @return {object} header with new session
127
+ * @private
128
+ */
129
+ _setHeader(session) {
130
+ return {
131
+ headers: {
132
+ authorization: session,
133
+ }
134
+ };
135
+ }
136
+
137
+ /**
138
+ * @description Send real time notification
139
+ * @param {object} params Params to send notification
140
+ * @param {string} params.userIds Users to send notification
141
+ * @param {object} params.message Object with data to send user
142
+ * @param {object} session Session, token JWT
143
+ * @returns {Promise&lt;*>}
144
+ */
145
+ async realTime(params, session) {
146
+ const self = this;
147
+
148
+ try {
149
+ Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
150
+ Joi.assert(params.userIds, Joi.array().required(), 'OrgId of the user SU');
151
+ Joi.assert(params.message, Joi.object().required(), 'Object with data to send user');
152
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
153
+
154
+ const apiCall = self.client.post(`/admin/send/notifications`, params, self._setHeader(session));
155
+ return self._returnData(await apiCall);
156
+ } catch (ex) {
157
+ throw ex;
158
+ }
159
+ }
160
+
161
+ /**
162
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
163
+ * @description Create notification
164
+ * @param {object} params Params to create notification
165
+ * @param {string} params.orgId OrgId of the user SU
166
+ * @param {string} params.userId User to create notification
167
+ * @param {object} params.message Object with data to send user
168
+ * @param {string} session Session, token JWT
169
+ * @return {Promise}
170
+ * @public
171
+ * @async
172
+ * @example
173
+ *
174
+ * const API = require('@docbrasil/api-systemmanager');
175
+ * const api = new API();
176
+ * const params = {
177
+ * orgId: '5edd11c46b6ce9729c2c297c',
178
+ * userId: '55e4a3bd6be6b45210833fae',
179
+ * message: 'Olá como vai tudo bem?'
180
+ * };
181
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
182
+ * await api.admin.notifications.add(params, session);
183
+ */
184
+ async add(params, session) {
185
+ const self = this;
186
+
187
+ try {
188
+ Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
189
+ Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
190
+ Joi.assert(params.userId, Joi.string().required(), 'User to create notification');
191
+ Joi.assert(params.message, Joi.object().required(), 'Object with data to send user');
192
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
193
+
194
+ const {orgId, ...notificationPayload} = params;
195
+ const apiCall = self.client.post(`/admin/organizations/${orgId}/notifications`, notificationPayload, self._setHeader(session));
196
+ return self._returnData(await apiCall);
197
+ } catch (ex) {
198
+ throw ex;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
204
+ * @description Search notification using (notificationId or userId)
205
+ * @param {object} params Params to create notification
206
+ * @param {string} params.orgId OrgId of the user SU
207
+ * @param {string} params.id ALERT! Id is userId or id is notificationId
208
+ * @param {string} session Session, token JWT
209
+ * @return {Promise}
210
+ * @public
211
+ * @async
212
+ * @example
213
+ *
214
+ * const API = require('@docbrasil/api-systemmanager');
215
+ * const api = new API();
216
+ * const params = {
217
+ * orgId: '5edd11c46b6ce9729c2c297c',
218
+ * id: '55e4a3bd6be6b45210833fae',
219
+ * };
220
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
221
+ * await api.admin.notifications.findById(params, session);
222
+ */
223
+ async findById(params, session) {
224
+ const self = this;
225
+
226
+ try {
227
+ Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
228
+ Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
229
+ Joi.assert(params.id, Joi.string().required(), 'ALERT! Id is userId or id is notificationId');
230
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
231
+
232
+ const {orgId, id} = params;
233
+ const apiCall = self.client.get(`/admin/organizations/${orgId}/notifications/${id}`, self._setHeader(session));
234
+ return self._returnData(await apiCall);
235
+ } catch (ex) {
236
+ throw ex;
237
+ }
238
+ }
239
+
240
+ /**
241
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
242
+ * @description Update notification using (notificationId or userId)
243
+ * @param {object} params Params to create notification
244
+ * @param {string} params.orgId OrgId of the user SU
245
+ * @param {string} params.id ALERT! Id is userId or id is notificationId
246
+ * @param {boolean} params.read If message is read true or false
247
+ * @param {string} session Session, token JWT
248
+ * @return {Promise}
249
+ * @public
250
+ * @async
251
+ * @example
252
+ *
253
+ * const API = require('@docbrasil/api-systemmanager');
254
+ * const api = new API();
255
+ * const params = {
256
+ * orgId: '5edd11c46b6ce9729c2c297c',
257
+ * id: '55e4a3bd6be6b45210833fae',
258
+ * read: true
259
+ * };
260
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
261
+ * await api.admin.notifications.findByIdAndUpdate(params, session);
262
+ */
263
+ async findByIdAndUpdate(params, session) {
264
+ const self = this;
265
+
266
+ try {
267
+ Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
268
+ Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
269
+ Joi.assert(params.id, Joi.string().required(), 'ALERT! Id is userId or id is notificationId');
270
+ Joi.assert(params.read, Joi.boolean().required(), 'If message is read true or false');
271
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
272
+
273
+ const {orgId, id, ...statusPayload} = params;
274
+ const apiCall = self.client.put(`/admin/organizations/${orgId}/notifications/${id}`, statusPayload, self._setHeader(session));
275
+ return self._returnData(await apiCall);
276
+ } catch (ex) {
277
+ throw ex;
278
+ }
279
+ }
280
+
281
+ /**
282
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
283
+ * @description Delete notification using (notificationId or userId)
284
+ * @param {object} params Params to create notification
285
+ * @param {string} params.orgId OrgId of the user SU
286
+ * @param {string} params.id ALERT! Id is userId or id is notificationId
287
+ * @param {string} session Session, token JWT
288
+ * @return {Promise}
289
+ * @public
290
+ * @async
291
+ * @example
292
+ *
293
+ * const API = require('@docbrasil/api-systemmanager');
294
+ * const api = new API();
295
+ * const params = {
296
+ * orgId: '5edd11c46b6ce9729c2c297c',
297
+ * id: '55e4a3bd6be6b45210833fae',
298
+ * };
299
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
300
+ * await api.admin.notifications.findByIdAndDelete(params, session);
301
+ */
302
+ async findByIdAndRemove(params, session) {
303
+ const self = this;
304
+
305
+ try {
306
+ Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
307
+ Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
308
+ Joi.assert(params.id, Joi.string().required(), 'ALERT! Id is userId or id is notificationId');
309
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
310
+
311
+ const {orgId, id} = params;
312
+ const apiCall = self.client.delete(`/admin/organizations/${orgId}/notifications/${id}`, self._setHeader(session));
313
+ return self._returnData(await apiCall);
314
+ } catch (ex) {
315
+ throw ex;
316
+ }
317
+ }
318
+ }
319
+
320
+ export default AdminNotification;
321
+ </code></pre>
322
+ </article>
323
+ </section>
324
+
325
+
326
+
327
+
328
+ </div>
329
+
330
+ <footer class="footer">
331
+ <div class="content has-text-centered">
332
+ <p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a></p>
333
+ <p class="sidebar-created-by">
334
+ <a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
335
+ <a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
336
+ </p>
337
+ </div>
338
+ </footer>
339
+
340
+ </div>
341
+ <div id="side-nav" class="side-nav">
342
+ </div>
343
+ </div>
344
+ <script src="scripts/app.min.js"></script>
345
+ <script>PR.prettyPrint();</script>
346
+ <script src="scripts/linenumber.js"> </script>
347
+
348
+
349
+ </body>
350
+ </html>