@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.
- package/.github/workflows/static.yml +43 -0
- package/api/external.js +41 -0
- package/dist/bundle.cjs +41 -0
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +382 -0
- package/docs/Admin.html +336 -0
- package/docs/AdminDocuments.html +2235 -0
- package/docs/AdminForm.html +934 -0
- package/docs/AdminLists.html +895 -0
- package/docs/AdminMessage.html +1490 -0
- package/docs/AdminNotification.html +1636 -0
- package/docs/AdminPlugin.html +696 -0
- package/docs/AdminPolicy.html +451 -0
- package/docs/AdminProcesses.html +692 -0
- package/docs/AdminTask.html +740 -0
- package/docs/AdminUser.html +1203 -0
- package/docs/Datasource.html +660 -0
- package/docs/Dispatch.html +624 -0
- package/docs/Documents.html +4875 -0
- package/docs/External.html +1497 -0
- package/docs/GeoLocation.html +503 -0
- package/docs/Login.html +1839 -0
- package/docs/Notification.html +625 -0
- package/docs/Organization.html +2767 -0
- package/docs/Process.html +1598 -0
- package/docs/Register.html +1604 -0
- package/docs/Session.html +482 -0
- package/docs/Task.html +1394 -0
- package/docs/TaskAvailable.html +893 -0
- package/docs/User.html +2002 -0
- package/docs/Users.html +569 -0
- package/docs/admin_doctypes.js.html +193 -0
- package/docs/admin_document.js.html +449 -0
- package/docs/admin_form.js.html +268 -0
- package/docs/admin_index.js.html +163 -0
- package/docs/admin_list.js.html +250 -0
- package/docs/admin_message.js.html +311 -0
- package/docs/admin_notification.js.html +350 -0
- package/docs/admin_organization.js.html +241 -0
- package/docs/admin_plugin.js.html +233 -0
- package/docs/admin_policy.js.html +195 -0
- package/docs/admin_processes.js.html +487 -0
- package/docs/admin_task.js.html +242 -0
- package/docs/admin_user.js.html +302 -0
- package/docs/dispatch.js.html +218 -0
- package/docs/external.js.html +333 -0
- package/docs/general_geoLocation.js.html +205 -0
- package/docs/general_index.js.html +140 -0
- package/docs/index.html +129 -0
- package/docs/login.js.html +384 -0
- package/docs/scripts/app.min.js +1 -0
- package/docs/scripts/linenumber.js +26 -0
- package/docs/scripts/search.js +39 -0
- package/docs/session.js.html +202 -0
- package/docs/styles/app.min.css +1 -0
- package/docs/styles/iframe.css +13 -0
- package/docs/styles/prettify-jsdoc.css +111 -0
- package/docs/styles/prettify-tomorrow.css +132 -0
- package/docs/styles/reset.css +44 -0
- package/docs/user_datasource.js.html +261 -0
- package/docs/user_document.js.html +847 -0
- package/docs/user_index.js.html +156 -0
- package/docs/user_notification.js.html +218 -0
- package/docs/user_organization.js.html +347 -0
- package/docs/user_process.js.html +352 -0
- package/docs/user_register.js.html +322 -0
- package/docs/user_task.js.html +319 -0
- package/docs/user_task_available.js.html +252 -0
- package/docs/user_user.js.html +404 -0
- package/docs/utils_promises.js.html +235 -0
- package/package.json +7 -4
- package/readme.md +7 -8
- package/doc.md +0 -653
|
@@ -0,0 +1,347 @@
|
|
|
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> user/organization.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>user/organization.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
|
+
import Axios from 'axios';
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Class for organizations, permission user
|
|
95
|
+
* @class
|
|
96
|
+
*/
|
|
97
|
+
class Organization {
|
|
98
|
+
|
|
99
|
+
constructor(options) {
|
|
100
|
+
Joi.assert(options, Joi.object().required());
|
|
101
|
+
Joi.assert(options.parent, Joi.object().required());
|
|
102
|
+
|
|
103
|
+
const self = this;
|
|
104
|
+
self.parent = options.parent;
|
|
105
|
+
self._client = self.parent.dispatch.getClient();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
110
|
+
* @description Get the return data and check for errors
|
|
111
|
+
* @param {object} retData Response HTTP
|
|
112
|
+
* @return {*}
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
_returnData(retData, def = {}) {
|
|
116
|
+
if (retData.status !== 200) {
|
|
117
|
+
throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
|
|
118
|
+
} else {
|
|
119
|
+
return _.get(retData, 'data', def);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
125
|
+
* @description Set header with new session
|
|
126
|
+
* @param {string} session Session, token JWT
|
|
127
|
+
* @return {object} header with new session
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
_setHeader(session) {
|
|
131
|
+
return {
|
|
132
|
+
headers: {
|
|
133
|
+
authorization: session,
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
140
|
+
* @description Find organization by id
|
|
141
|
+
* @param {string} orgId ID of the organization to find (_id database)
|
|
142
|
+
* @param {string} session Is token JWT
|
|
143
|
+
* @public
|
|
144
|
+
* @async
|
|
145
|
+
* @example
|
|
146
|
+
*
|
|
147
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
148
|
+
* const api = new API();
|
|
149
|
+
* const orgId = '80443245000122';
|
|
150
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
151
|
+
* await api.user.organization.findById(idCard, session);
|
|
152
|
+
*/
|
|
153
|
+
async findById(orgId, session) {
|
|
154
|
+
const self = this;
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
Joi.assert(orgId, Joi.string().required(), 'orgId ID of the organization to find (_id database_');
|
|
158
|
+
Joi.assert(session, Joi.string().required(), 'SM session (JWT) to call API');
|
|
159
|
+
|
|
160
|
+
const apiCall = self._client.get(`/organizations/${orgId}`, self._setHeader(session));
|
|
161
|
+
return self._returnData(await apiCall);
|
|
162
|
+
} catch (ex) {
|
|
163
|
+
throw ex;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
169
|
+
* @description Check if id card exist
|
|
170
|
+
* @param {string} idcard Check if id card exist
|
|
171
|
+
* @param {string} session Is token JWT
|
|
172
|
+
* @public
|
|
173
|
+
* @async
|
|
174
|
+
* @example
|
|
175
|
+
*
|
|
176
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
177
|
+
* const api = new API();
|
|
178
|
+
* const idCard = '80443245000122';
|
|
179
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
180
|
+
* await api.user.organization.idCardExist(idCard, session);
|
|
181
|
+
*/
|
|
182
|
+
async idCardExist(idCard, session) {
|
|
183
|
+
const self = this;
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
Joi.assert(idCard, Joi.string().required(), 'Check if id card exist');
|
|
187
|
+
Joi.assert(session, Joi.string().required(), 'SM session (JWT) to call API');
|
|
188
|
+
|
|
189
|
+
const apiCall = self._client.get(`/organizations/exist/idcard/${idCard}`, self._setHeader(session));
|
|
190
|
+
return self._returnData(await apiCall);
|
|
191
|
+
} catch (ex) {
|
|
192
|
+
throw ex;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
198
|
+
* @description Update avatar of organization by session of user not allow session user SU
|
|
199
|
+
* @param {object} params Params to update avatar
|
|
200
|
+
* @param {string} params.avatar Image in base64 to update
|
|
201
|
+
* @param {string} params.type mimeType (image/png)
|
|
202
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
203
|
+
* @return {Promise}
|
|
204
|
+
* @public
|
|
205
|
+
* @async
|
|
206
|
+
* @example
|
|
207
|
+
*
|
|
208
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
209
|
+
* const api = new API();
|
|
210
|
+
* const params = {
|
|
211
|
+
* avatar: 'iVBORw0KGgoAAAANSUhEUgAAAasAAAHnCAYAAAAGi3J6AAA9BElEQVR...He3/kk/m7kl35S8AAAAASUVORK5CYII=',
|
|
212
|
+
* type: 'image/png',
|
|
213
|
+
* };
|
|
214
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
215
|
+
* await api.user.profile.updateAvatar(params, session);
|
|
216
|
+
*/
|
|
217
|
+
async upsertAvatar(params = {}, session) {
|
|
218
|
+
const self = this;
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
Joi.assert(params, Joi.object().required());
|
|
222
|
+
Joi.assert(params.avatar, Joi.string().required());
|
|
223
|
+
Joi.assert(params.type, Joi.string().required());
|
|
224
|
+
Joi.assert(session, Joi.string().required());
|
|
225
|
+
|
|
226
|
+
const {avatar, type} = params;
|
|
227
|
+
const payload = {avatar, type};
|
|
228
|
+
|
|
229
|
+
const apiCall = self._client.put('/organizations/1234567890/logo', payload, self._setHeader(session));
|
|
230
|
+
return self._returnData(await apiCall);
|
|
231
|
+
} catch (ex) {
|
|
232
|
+
throw ex;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
238
|
+
* @description Remove avatar of user by session of user not allow session user SU
|
|
239
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
240
|
+
* @return {Promise}
|
|
241
|
+
* @public
|
|
242
|
+
* @async
|
|
243
|
+
* @example
|
|
244
|
+
*
|
|
245
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
246
|
+
* const api = new API();
|
|
247
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
248
|
+
* await api.user.profile.removeAvatar(session);
|
|
249
|
+
*/
|
|
250
|
+
async removeAvatar(session) {
|
|
251
|
+
const self = this;
|
|
252
|
+
|
|
253
|
+
try {
|
|
254
|
+
Joi.assert(session, Joi.string().required());
|
|
255
|
+
|
|
256
|
+
const apiCall = self._client.delete('/organizations/1234567890/logo', self._setHeader(session));
|
|
257
|
+
return self._returnData(await apiCall);
|
|
258
|
+
} catch (ex) {
|
|
259
|
+
throw ex;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @author Thiago Anselmo <thiagoo.anselmoo@gmail.com>
|
|
265
|
+
* @description Call URL internal, need auth JWT (session)
|
|
266
|
+
* @param {!object} params Params to call fectch (URL internal)
|
|
267
|
+
* @param {!string} params.url URL to call
|
|
268
|
+
* @param {!string} [params.method=POST] Fetch Method
|
|
269
|
+
* @param {string} params.payload Payload to send system manager
|
|
270
|
+
* @returns {promise}
|
|
271
|
+
* @public
|
|
272
|
+
* @async
|
|
273
|
+
* @example
|
|
274
|
+
*
|
|
275
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
276
|
+
* const api = new API();
|
|
277
|
+
*
|
|
278
|
+
* const params = {
|
|
279
|
+
* url: 'http://localhost:8080/organizations/..../process/..../task/candidateAccepted/end/....',
|
|
280
|
+
* method: 'POST'
|
|
281
|
+
* }
|
|
282
|
+
* await api.user.organization.callFetchs(params, session);
|
|
283
|
+
*/
|
|
284
|
+
async callFetch(params, session) {
|
|
285
|
+
const self = this;
|
|
286
|
+
|
|
287
|
+
try {
|
|
288
|
+
Joi.assert(params, Joi.object().required(), 'Params to call fectch (URL internal)');
|
|
289
|
+
Joi.assert(params.url, Joi.string().required(), 'URL to call');
|
|
290
|
+
Joi.assert(params.method, Joi.string(), 'Fetch Method');
|
|
291
|
+
Joi.assert(params.payload, Joi.object(), 'Payload to send system manager');
|
|
292
|
+
Joi.assert(session, Joi.string().required(), 'Session to call');
|
|
293
|
+
|
|
294
|
+
const {url, payload = {}} = params;
|
|
295
|
+
let {method} = params;
|
|
296
|
+
|
|
297
|
+
method = method.toLowerCase();
|
|
298
|
+
const methodWithPayload = ['post', 'put'];
|
|
299
|
+
|
|
300
|
+
const options = {
|
|
301
|
+
method,
|
|
302
|
+
headers: {authorization: session},
|
|
303
|
+
url,
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
if (methodWithPayload.indexOf(method) !== -1)
|
|
307
|
+
options.data = payload;
|
|
308
|
+
|
|
309
|
+
return await self._returnData(await Axios(options));
|
|
310
|
+
|
|
311
|
+
} catch (ex) {
|
|
312
|
+
throw ex;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export default Organization;
|
|
318
|
+
</code></pre>
|
|
319
|
+
</article>
|
|
320
|
+
</section>
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
</div>
|
|
326
|
+
|
|
327
|
+
<footer class="footer">
|
|
328
|
+
<div class="content has-text-centered">
|
|
329
|
+
<p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a></p>
|
|
330
|
+
<p class="sidebar-created-by">
|
|
331
|
+
<a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
|
|
332
|
+
<a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
|
|
333
|
+
</p>
|
|
334
|
+
</div>
|
|
335
|
+
</footer>
|
|
336
|
+
|
|
337
|
+
</div>
|
|
338
|
+
<div id="side-nav" class="side-nav">
|
|
339
|
+
</div>
|
|
340
|
+
</div>
|
|
341
|
+
<script src="scripts/app.min.js"></script>
|
|
342
|
+
<script>PR.prettyPrint();</script>
|
|
343
|
+
<script src="scripts/linenumber.js"> </script>
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
</body>
|
|
347
|
+
</html>
|