@docbrasil/api-systemmanager 1.0.52 → 1.0.55
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/api/admin/index.js +6 -5
- package/api/admin/organization.js +124 -0
- package/package.json +1 -1
package/api/admin/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
1
|
import Joi from 'joi';
|
|
3
2
|
|
|
4
3
|
import AdminDocument from './document';
|
|
@@ -12,6 +11,7 @@ import AdminUser from './user';
|
|
|
12
11
|
import AdminProcesses from './processes';
|
|
13
12
|
import AdminMessage from './message';
|
|
14
13
|
import AdminDocTypes from './doctypes';
|
|
14
|
+
import AdminOrganizations from './organization';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @class API request, admin permission level
|
|
@@ -28,17 +28,18 @@ class Admin {
|
|
|
28
28
|
Joi.assert(options.parent, Joi.object().required());
|
|
29
29
|
|
|
30
30
|
const self = this;
|
|
31
|
+
self.doctypes = new AdminDocTypes(options);
|
|
31
32
|
self.document = new AdminDocument(options);
|
|
32
33
|
self.form = new AdminForm(options);
|
|
33
|
-
self.notification = new AdminNotification(options);
|
|
34
34
|
self.list = new AdminList(options);
|
|
35
|
+
self.message = new AdminMessage(options);
|
|
36
|
+
self.organizations = new AdminOrganizations(options);
|
|
37
|
+
self.notification = new AdminNotification(options);
|
|
35
38
|
self.plugin = new AdminPlugin(options);
|
|
36
39
|
self.policy = new AdminPolicy(options);
|
|
40
|
+
self.processes = new AdminProcesses(options);
|
|
37
41
|
self.task = new AdminTask(options);
|
|
38
42
|
self.user = new AdminUser(options);
|
|
39
|
-
self.processes = new AdminProcesses(options);
|
|
40
|
-
self.message = new AdminMessage(options);
|
|
41
|
-
self.doctypes = new AdminDocTypes(options);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Boom from '@hapi/boom';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Class for organizations, permission user
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class Organization {
|
|
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
|
+
throw 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 CloudBrasil <abernardo.br@gmail.com>
|
|
52
|
+
* @description Update avatar of organization by session of user not allow session user SU
|
|
53
|
+
* @param {object} params Params to update avatar
|
|
54
|
+
* @param {string} params.orgId - Organization id
|
|
55
|
+
* @param {string} params.avatar - Image in base64 to update
|
|
56
|
+
* @param {string} params.type - MimeType (image/png)
|
|
57
|
+
* @param {string} session - Is token JWT of user SU
|
|
58
|
+
* @return {Promise}
|
|
59
|
+
* @public
|
|
60
|
+
* @async
|
|
61
|
+
* @example
|
|
62
|
+
*
|
|
63
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
64
|
+
* const api = new API();
|
|
65
|
+
* const params = {
|
|
66
|
+
* orgId: '5dadd01dc4af3941d42f8c5c',
|
|
67
|
+
* avatar: 'iVBORw0KGgoAAAANSUhEUgAAAasAAAHnCAYAAAAGi3J6AAA9BElEQVR...He3/kk/m7kl35S8AAAAASUVORK5CYII=',
|
|
68
|
+
* type: 'image/png',
|
|
69
|
+
* };
|
|
70
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
71
|
+
* await api.admin.organizations.upsertAvatar(params, session);
|
|
72
|
+
*/
|
|
73
|
+
async upsertAvatar(params = {}, session) {
|
|
74
|
+
const self = this;
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
Joi.assert(params, Joi.object().required());
|
|
78
|
+
Joi.assert(params.orgId, Joi.string().required(), 'Organization id');
|
|
79
|
+
Joi.assert(params.avatar, Joi.string().required(), 'Image in base64 to update');
|
|
80
|
+
Joi.assert(params.type, Joi.string().required(), 'MimeType (image/png)');
|
|
81
|
+
Joi.assert(session, Joi.string().required(), 'Is token JWT of user SU');
|
|
82
|
+
|
|
83
|
+
const {orgId, avatar, type} = params;
|
|
84
|
+
const payload = {avatar, type};
|
|
85
|
+
|
|
86
|
+
const apiCall = self._client.put(`/admin/organizations/${orgId}/logo`, payload, self._setHeader(session));
|
|
87
|
+
return self._returnData(await apiCall);
|
|
88
|
+
} catch (ex) {
|
|
89
|
+
throw ex;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
95
|
+
* @description Remove avatar of user by session of user not allow session user SU
|
|
96
|
+
* @param {string} params.orgId - Organization id
|
|
97
|
+
* @param {string} session - Is token JWT of user SU
|
|
98
|
+
* @return {Promise}
|
|
99
|
+
* @public
|
|
100
|
+
* @async
|
|
101
|
+
* @example
|
|
102
|
+
*
|
|
103
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
104
|
+
* const api = new API();
|
|
105
|
+
* const orgId = '5dadd01dc4af3941d42f8c5c';
|
|
106
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
107
|
+
* await api.admin.organizations.removeAvatar(orgId, session);
|
|
108
|
+
*/
|
|
109
|
+
async removeAvatar(orgId, session) {
|
|
110
|
+
const self = this;
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
Joi.assert(orgId, Joi.string().required(), 'Organization id');
|
|
114
|
+
Joi.assert(session, Joi.string().required(), 'Is token JWT of user SU');
|
|
115
|
+
|
|
116
|
+
const apiCall = self._client.delete(`/admin/organizations/${orgId}/logo`, self._setHeader(session));
|
|
117
|
+
return self._returnData(await apiCall);
|
|
118
|
+
} catch (ex) {
|
|
119
|
+
throw ex;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export default Organization;
|
package/package.json
CHANGED