@docbrasil/api-systemmanager 1.0.93 → 1.0.94
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/doctypes.js +76 -76
- package/api/admin/document.js +332 -332
- package/api/admin/form.js +151 -151
- package/api/admin/index.js +46 -46
- package/api/admin/list.js +133 -133
- package/api/admin/message.js +194 -194
- package/api/admin/notification.js +233 -233
- package/api/admin/organization.js +124 -124
- package/api/admin/plugin.js +116 -116
- package/api/admin/policy.js +78 -78
- package/api/admin/processes.js +370 -370
- package/api/admin/task.js +125 -125
- package/api/admin/user.js +185 -185
- package/api/dispatch.js +101 -101
- package/api/general/geoLocation.js +88 -88
- package/api/general/index.js +23 -23
- package/api/login.js +267 -267
- package/api/session.js +85 -85
- package/api/user/datasource.js +144 -144
- package/api/user/document.js +730 -730
- package/api/user/index.js +39 -39
- package/api/user/notification.js +101 -101
- package/api/user/organization.js +230 -230
- package/api/user/process.js +191 -191
- package/api/user/register.js +205 -205
- package/api/user/task.js +201 -201
- package/api/user/task_available.js +135 -135
- package/api/user/user.js +287 -287
- package/api/utils/cypher.js +37 -37
- package/api/utils/promises.js +118 -118
- package/bundleRollup.js +158 -158
- package/dist/bundle.cjs +4875 -4875
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +336 -674
- package/doc.md +653 -653
- package/helper/boom.js +487 -487
- package/helper/cryptojs.js +6067 -6067
- package/index.js +85 -85
- package/package-lock.json +4635 -4635
- package/package.json +68 -68
- package/readme.md +25 -25
- package/tests/admin/document.spec.js +45 -45
- package/tests/admin/form.spec.js +74 -74
- package/tests/admin/list.spec.js +86 -86
- package/tests/admin/message.js +92 -92
- package/tests/admin/notification.spec.js +174 -174
- package/tests/admin/pluginspec..js +71 -71
- package/tests/admin/policy.spec.js +71 -71
- package/tests/admin/processes.spec.js +119 -119
- package/tests/admin/users.spec.js +127 -127
- package/tests/documents.spec.js +164 -164
- package/tests/login.spec.js +91 -91
- package/tests/session.spec..js +58 -58
- package/tests/user/documents.js +164 -164
- package/tests/user/organization.js +122 -122
- package/tests/user/process.js +71 -71
- package/tests/user/task_available.js +75 -75
- package/tests/user/user.js +88 -88
package/api/user/user.js
CHANGED
|
@@ -1,287 +1,287 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import Boom from '@hapi/boom';
|
|
3
|
-
import Joi from 'joi';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Class for user, permission user
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class User {
|
|
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
|
-
self.gender = {
|
|
19
|
-
male: 1,
|
|
20
|
-
female: 2,
|
|
21
|
-
nonBinary: 3
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
27
|
-
* @description Get the return data and check for errors
|
|
28
|
-
* @param {object} retData Response HTTP
|
|
29
|
-
* @return {*}
|
|
30
|
-
* @private
|
|
31
|
-
*/
|
|
32
|
-
_returnData(retData, def = {}) {
|
|
33
|
-
if (retData.status !== 200) {
|
|
34
|
-
return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
|
|
35
|
-
} else {
|
|
36
|
-
return _.get(retData, 'data', def);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
42
|
-
* @description Set header with new session
|
|
43
|
-
* @param {string} session Session, token JWT
|
|
44
|
-
* @return {object} header with new session
|
|
45
|
-
* @private
|
|
46
|
-
*/
|
|
47
|
-
_setHeader(session) {
|
|
48
|
-
return {
|
|
49
|
-
headers: {
|
|
50
|
-
authorization: session,
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
57
|
-
* @description Update avatar of user by session of user not allow session user SU
|
|
58
|
-
* @param {object} params Params to update avatar
|
|
59
|
-
* @param {string} params.avatar Image in base64 to update
|
|
60
|
-
* @param {string} params.type mimeType (image/png)
|
|
61
|
-
* @param {string} session Is token JWT of user NOT allow SU
|
|
62
|
-
* @return {Promise}
|
|
63
|
-
* @public
|
|
64
|
-
* @async
|
|
65
|
-
* @example
|
|
66
|
-
*
|
|
67
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
68
|
-
* const api = new API();
|
|
69
|
-
* const params = {
|
|
70
|
-
* avatar: '55e4a3bd6be6b45210833fae',
|
|
71
|
-
* type: '123456',
|
|
72
|
-
* };
|
|
73
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
74
|
-
* await api.user.profile.updateAvatar(params, session);
|
|
75
|
-
*/
|
|
76
|
-
async updateAvatar(params, session) {
|
|
77
|
-
const self = this;
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
Joi.assert(params, Joi.object().required());
|
|
81
|
-
Joi.assert(params.avatar, Joi.string().required());
|
|
82
|
-
Joi.assert(params.type, Joi.string().required());
|
|
83
|
-
Joi.assert(session, Joi.string().required());
|
|
84
|
-
|
|
85
|
-
const {avatar, type} = params;
|
|
86
|
-
const payload = {avatar, type};
|
|
87
|
-
|
|
88
|
-
const apiCall = self._client.post(`/users/avatar`, payload, self._setHeader(session));
|
|
89
|
-
return self._returnData(await apiCall);
|
|
90
|
-
} catch (ex) {
|
|
91
|
-
throw ex;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
97
|
-
* @description Remove avatar of user by session of user not allow session user SU
|
|
98
|
-
* @param {string} session Is token JWT of user NOT allow SU
|
|
99
|
-
* @return {Promise}
|
|
100
|
-
* @public
|
|
101
|
-
* @async
|
|
102
|
-
* @example
|
|
103
|
-
*
|
|
104
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
105
|
-
* const api = new API();
|
|
106
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
107
|
-
* await api.user.profile.removeAvatar(session);
|
|
108
|
-
*/
|
|
109
|
-
async removeAvatar(session) {
|
|
110
|
-
const self = this;
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
Joi.assert(session, Joi.string().required());
|
|
114
|
-
|
|
115
|
-
const apiCall = self._client.delete(`/users/avatar`, self._setHeader(session));
|
|
116
|
-
return self._returnData(await apiCall);
|
|
117
|
-
} catch (ex) {
|
|
118
|
-
throw ex;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
124
|
-
* @description Remove the signature of user by session
|
|
125
|
-
* @param {string} session Is token JWT of user NOT allow SU
|
|
126
|
-
* @return {Promise}
|
|
127
|
-
* @public
|
|
128
|
-
* @async
|
|
129
|
-
* @example
|
|
130
|
-
*
|
|
131
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
132
|
-
* const api = new API();
|
|
133
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
134
|
-
* await api.user.profile.removeSignature(session);
|
|
135
|
-
*/
|
|
136
|
-
async removeSignature(session) {
|
|
137
|
-
const self = this;
|
|
138
|
-
|
|
139
|
-
try {
|
|
140
|
-
Joi.assert(session, Joi.string().required());
|
|
141
|
-
|
|
142
|
-
const apiCall = self._client.delete(`/users/signature`, self._setHeader(session));
|
|
143
|
-
return self._returnData(await apiCall);
|
|
144
|
-
} catch (ex) {
|
|
145
|
-
throw ex;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
151
|
-
* @description Sava a new signature of user by session
|
|
152
|
-
* @param {object} data The signature data to save
|
|
153
|
-
* @param {string} data.type CURSIVE or HANDWRITE
|
|
154
|
-
* @param {string} data.file CURSIVE the <fontname>:<name used on the signature>
|
|
155
|
-
* HANDWRITE the base 64 image (w/o the mime a base prefix)
|
|
156
|
-
* @param {string} session Is token JWT of user NOT allow SU
|
|
157
|
-
* @return {Promise}
|
|
158
|
-
* @public
|
|
159
|
-
* @async
|
|
160
|
-
* @example
|
|
161
|
-
*
|
|
162
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
163
|
-
* const api = new API();
|
|
164
|
-
* const data = {
|
|
165
|
-
* type: 'CURSIVE',
|
|
166
|
-
* file: 'allura:Mary John Heart'
|
|
167
|
-
* };
|
|
168
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
169
|
-
* await api.user.profile.saveSignature(data, session);
|
|
170
|
-
*
|
|
171
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
172
|
-
* const api = new API();
|
|
173
|
-
* const data = {
|
|
174
|
-
* type: 'HANDWRITE',
|
|
175
|
-
* file: 'iVBORw0KGgoAAAANSUhEUgAAAj...'
|
|
176
|
-
* };
|
|
177
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
178
|
-
* await api.user.profile.saveSignature(session);
|
|
179
|
-
*/
|
|
180
|
-
async saveSignature(data, session) {
|
|
181
|
-
const self = this;
|
|
182
|
-
|
|
183
|
-
try {
|
|
184
|
-
Joi.assert(data, Joi.object().required());
|
|
185
|
-
Joi.assert(data.type, Joi.string().required());
|
|
186
|
-
Joi.assert(data.file, Joi.string().required());
|
|
187
|
-
Joi.assert(session, Joi.string().required());
|
|
188
|
-
|
|
189
|
-
const apiCall = self._client.put(`/users/signature`, data, 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 a user profile by id
|
|
199
|
-
* @param {object} params Params to update task
|
|
200
|
-
* @param {string} params.name The name of the user
|
|
201
|
-
* @param {string} params.site The site of the user
|
|
202
|
-
* @param {string} params.faceboook The faceboook of the user
|
|
203
|
-
* @param {string} params.linkedin The linkedin of the user
|
|
204
|
-
* @param {date} params.dob The date of birth of the user
|
|
205
|
-
* @param {number<UserGender>} params.gender The gender of of the user self.gender
|
|
206
|
-
* @param {string} params.phone The phone
|
|
207
|
-
* @param {string} params.phone2 The phone 2
|
|
208
|
-
* @param {string} params.phone3 The phone 3
|
|
209
|
-
* @param {string} params.password The password to change
|
|
210
|
-
* @param {string} params.secQuestion The security question
|
|
211
|
-
* @param {string} params.secAnswer The security answer
|
|
212
|
-
* @param {string} params.timezone The timezone
|
|
213
|
-
* @param {string} params.userLanguage The user language
|
|
214
|
-
* @param {string} params.changePassword (required) If we need to change the status and we changed the password
|
|
215
|
-
* @param {string} params.acceptTermsOfUse If the user has accepted the terms of change
|
|
216
|
-
* @param {string} session Session, token JWT
|
|
217
|
-
* @return {Promise<void>}
|
|
218
|
-
* @public
|
|
219
|
-
* @async
|
|
220
|
-
* @example
|
|
221
|
-
*
|
|
222
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
223
|
-
* const api = new API();
|
|
224
|
-
* const params = {
|
|
225
|
-
* name: 'New Name'
|
|
226
|
-
* };
|
|
227
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
228
|
-
* await api.user.profile.findByIdAndUpdate(params, session);
|
|
229
|
-
*/
|
|
230
|
-
async findByIdAndUpdate(params = {}, session) {
|
|
231
|
-
const self = this;
|
|
232
|
-
|
|
233
|
-
try {
|
|
234
|
-
Joi.assert(session, Joi.string().required());
|
|
235
|
-
Joi.assert(params, Joi.object().required());
|
|
236
|
-
Joi.assert(params.changePassword, Joi.boolean().required());
|
|
237
|
-
|
|
238
|
-
if(_.isEmpty(params)) return;
|
|
239
|
-
|
|
240
|
-
const { changePassword = false, password = '' } = params;
|
|
241
|
-
|
|
242
|
-
if(changePassword && password === '') {
|
|
243
|
-
throw new Error('It is required to change the password')
|
|
244
|
-
} else {
|
|
245
|
-
params.changePassword = false;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const url = 'users';
|
|
249
|
-
const apiCall = self._client.put(url, params, self._setHeader(session));
|
|
250
|
-
return self._returnData(await apiCall);
|
|
251
|
-
} catch (ex) {
|
|
252
|
-
throw ex;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
258
|
-
* @description Change a user's organization
|
|
259
|
-
* @param {string} id Organization id
|
|
260
|
-
* @param {string} session Is token JWT of user NOT allow SU
|
|
261
|
-
* @return {Promise}
|
|
262
|
-
* @public
|
|
263
|
-
* @async
|
|
264
|
-
* @example
|
|
265
|
-
*
|
|
266
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
267
|
-
* const api = new API();
|
|
268
|
-
* const id = '616eccaaa9360a05293b10fe';
|
|
269
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
270
|
-
* await api.user.changeOrganization.updateAvatar(id, session);
|
|
271
|
-
*/
|
|
272
|
-
async changeOrganization(id, session) {
|
|
273
|
-
const self = this;
|
|
274
|
-
|
|
275
|
-
try {
|
|
276
|
-
Joi.assert(id, Joi.string().required());
|
|
277
|
-
Joi.assert(session, Joi.string().required());
|
|
278
|
-
|
|
279
|
-
const apiCall = self._client.put(`/organizations/${id}/change`, null, self._setHeader(session));
|
|
280
|
-
return self._returnData(await apiCall);
|
|
281
|
-
} catch (ex) {
|
|
282
|
-
throw ex;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
export default User;
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Boom from '@hapi/boom';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Class for user, permission user
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class User {
|
|
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
|
+
self.gender = {
|
|
19
|
+
male: 1,
|
|
20
|
+
female: 2,
|
|
21
|
+
nonBinary: 3
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
27
|
+
* @description Get the return data and check for errors
|
|
28
|
+
* @param {object} retData Response HTTP
|
|
29
|
+
* @return {*}
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
_returnData(retData, def = {}) {
|
|
33
|
+
if (retData.status !== 200) {
|
|
34
|
+
return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
|
|
35
|
+
} else {
|
|
36
|
+
return _.get(retData, 'data', def);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
42
|
+
* @description Set header with new session
|
|
43
|
+
* @param {string} session Session, token JWT
|
|
44
|
+
* @return {object} header with new session
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
_setHeader(session) {
|
|
48
|
+
return {
|
|
49
|
+
headers: {
|
|
50
|
+
authorization: session,
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
57
|
+
* @description Update avatar of user by session of user not allow session user SU
|
|
58
|
+
* @param {object} params Params to update avatar
|
|
59
|
+
* @param {string} params.avatar Image in base64 to update
|
|
60
|
+
* @param {string} params.type mimeType (image/png)
|
|
61
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
62
|
+
* @return {Promise}
|
|
63
|
+
* @public
|
|
64
|
+
* @async
|
|
65
|
+
* @example
|
|
66
|
+
*
|
|
67
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
68
|
+
* const api = new API();
|
|
69
|
+
* const params = {
|
|
70
|
+
* avatar: '55e4a3bd6be6b45210833fae',
|
|
71
|
+
* type: '123456',
|
|
72
|
+
* };
|
|
73
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
74
|
+
* await api.user.profile.updateAvatar(params, session);
|
|
75
|
+
*/
|
|
76
|
+
async updateAvatar(params, session) {
|
|
77
|
+
const self = this;
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
Joi.assert(params, Joi.object().required());
|
|
81
|
+
Joi.assert(params.avatar, Joi.string().required());
|
|
82
|
+
Joi.assert(params.type, Joi.string().required());
|
|
83
|
+
Joi.assert(session, Joi.string().required());
|
|
84
|
+
|
|
85
|
+
const {avatar, type} = params;
|
|
86
|
+
const payload = {avatar, type};
|
|
87
|
+
|
|
88
|
+
const apiCall = self._client.post(`/users/avatar`, payload, self._setHeader(session));
|
|
89
|
+
return self._returnData(await apiCall);
|
|
90
|
+
} catch (ex) {
|
|
91
|
+
throw ex;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
97
|
+
* @description Remove avatar of user by session of user not allow session user SU
|
|
98
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
99
|
+
* @return {Promise}
|
|
100
|
+
* @public
|
|
101
|
+
* @async
|
|
102
|
+
* @example
|
|
103
|
+
*
|
|
104
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
105
|
+
* const api = new API();
|
|
106
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
107
|
+
* await api.user.profile.removeAvatar(session);
|
|
108
|
+
*/
|
|
109
|
+
async removeAvatar(session) {
|
|
110
|
+
const self = this;
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
Joi.assert(session, Joi.string().required());
|
|
114
|
+
|
|
115
|
+
const apiCall = self._client.delete(`/users/avatar`, self._setHeader(session));
|
|
116
|
+
return self._returnData(await apiCall);
|
|
117
|
+
} catch (ex) {
|
|
118
|
+
throw ex;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
124
|
+
* @description Remove the signature of user by session
|
|
125
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
126
|
+
* @return {Promise}
|
|
127
|
+
* @public
|
|
128
|
+
* @async
|
|
129
|
+
* @example
|
|
130
|
+
*
|
|
131
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
132
|
+
* const api = new API();
|
|
133
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
134
|
+
* await api.user.profile.removeSignature(session);
|
|
135
|
+
*/
|
|
136
|
+
async removeSignature(session) {
|
|
137
|
+
const self = this;
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
Joi.assert(session, Joi.string().required());
|
|
141
|
+
|
|
142
|
+
const apiCall = self._client.delete(`/users/signature`, self._setHeader(session));
|
|
143
|
+
return self._returnData(await apiCall);
|
|
144
|
+
} catch (ex) {
|
|
145
|
+
throw ex;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
151
|
+
* @description Sava a new signature of user by session
|
|
152
|
+
* @param {object} data The signature data to save
|
|
153
|
+
* @param {string} data.type CURSIVE or HANDWRITE
|
|
154
|
+
* @param {string} data.file CURSIVE the <fontname>:<name used on the signature>
|
|
155
|
+
* HANDWRITE the base 64 image (w/o the mime a base prefix)
|
|
156
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
157
|
+
* @return {Promise}
|
|
158
|
+
* @public
|
|
159
|
+
* @async
|
|
160
|
+
* @example
|
|
161
|
+
*
|
|
162
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
163
|
+
* const api = new API();
|
|
164
|
+
* const data = {
|
|
165
|
+
* type: 'CURSIVE',
|
|
166
|
+
* file: 'allura:Mary John Heart'
|
|
167
|
+
* };
|
|
168
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
169
|
+
* await api.user.profile.saveSignature(data, session);
|
|
170
|
+
*
|
|
171
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
172
|
+
* const api = new API();
|
|
173
|
+
* const data = {
|
|
174
|
+
* type: 'HANDWRITE',
|
|
175
|
+
* file: 'iVBORw0KGgoAAAANSUhEUgAAAj...'
|
|
176
|
+
* };
|
|
177
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
178
|
+
* await api.user.profile.saveSignature(session);
|
|
179
|
+
*/
|
|
180
|
+
async saveSignature(data, session) {
|
|
181
|
+
const self = this;
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
Joi.assert(data, Joi.object().required());
|
|
185
|
+
Joi.assert(data.type, Joi.string().required());
|
|
186
|
+
Joi.assert(data.file, Joi.string().required());
|
|
187
|
+
Joi.assert(session, Joi.string().required());
|
|
188
|
+
|
|
189
|
+
const apiCall = self._client.put(`/users/signature`, data, 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 a user profile by id
|
|
199
|
+
* @param {object} params Params to update task
|
|
200
|
+
* @param {string} params.name The name of the user
|
|
201
|
+
* @param {string} params.site The site of the user
|
|
202
|
+
* @param {string} params.faceboook The faceboook of the user
|
|
203
|
+
* @param {string} params.linkedin The linkedin of the user
|
|
204
|
+
* @param {date} params.dob The date of birth of the user
|
|
205
|
+
* @param {number<UserGender>} params.gender The gender of of the user self.gender
|
|
206
|
+
* @param {string} params.phone The phone
|
|
207
|
+
* @param {string} params.phone2 The phone 2
|
|
208
|
+
* @param {string} params.phone3 The phone 3
|
|
209
|
+
* @param {string} params.password The password to change
|
|
210
|
+
* @param {string} params.secQuestion The security question
|
|
211
|
+
* @param {string} params.secAnswer The security answer
|
|
212
|
+
* @param {string} params.timezone The timezone
|
|
213
|
+
* @param {string} params.userLanguage The user language
|
|
214
|
+
* @param {string} params.changePassword (required) If we need to change the status and we changed the password
|
|
215
|
+
* @param {string} params.acceptTermsOfUse If the user has accepted the terms of change
|
|
216
|
+
* @param {string} session Session, token JWT
|
|
217
|
+
* @return {Promise<void>}
|
|
218
|
+
* @public
|
|
219
|
+
* @async
|
|
220
|
+
* @example
|
|
221
|
+
*
|
|
222
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
223
|
+
* const api = new API();
|
|
224
|
+
* const params = {
|
|
225
|
+
* name: 'New Name'
|
|
226
|
+
* };
|
|
227
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
228
|
+
* await api.user.profile.findByIdAndUpdate(params, session);
|
|
229
|
+
*/
|
|
230
|
+
async findByIdAndUpdate(params = {}, session) {
|
|
231
|
+
const self = this;
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
Joi.assert(session, Joi.string().required());
|
|
235
|
+
Joi.assert(params, Joi.object().required());
|
|
236
|
+
Joi.assert(params.changePassword, Joi.boolean().required());
|
|
237
|
+
|
|
238
|
+
if(_.isEmpty(params)) return;
|
|
239
|
+
|
|
240
|
+
const { changePassword = false, password = '' } = params;
|
|
241
|
+
|
|
242
|
+
if(changePassword && password === '') {
|
|
243
|
+
throw new Error('It is required to change the password')
|
|
244
|
+
} else {
|
|
245
|
+
params.changePassword = false;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const url = 'users';
|
|
249
|
+
const apiCall = self._client.put(url, params, self._setHeader(session));
|
|
250
|
+
return self._returnData(await apiCall);
|
|
251
|
+
} catch (ex) {
|
|
252
|
+
throw ex;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
258
|
+
* @description Change a user's organization
|
|
259
|
+
* @param {string} id Organization id
|
|
260
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
261
|
+
* @return {Promise}
|
|
262
|
+
* @public
|
|
263
|
+
* @async
|
|
264
|
+
* @example
|
|
265
|
+
*
|
|
266
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
267
|
+
* const api = new API();
|
|
268
|
+
* const id = '616eccaaa9360a05293b10fe';
|
|
269
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
270
|
+
* await api.user.changeOrganization.updateAvatar(id, session);
|
|
271
|
+
*/
|
|
272
|
+
async changeOrganization(id, session) {
|
|
273
|
+
const self = this;
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
Joi.assert(id, Joi.string().required());
|
|
277
|
+
Joi.assert(session, Joi.string().required());
|
|
278
|
+
|
|
279
|
+
const apiCall = self._client.put(`/organizations/${id}/change`, null, self._setHeader(session));
|
|
280
|
+
return self._returnData(await apiCall);
|
|
281
|
+
} catch (ex) {
|
|
282
|
+
throw ex;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export default User;
|
package/api/utils/cypher.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import CryptoJS from 'crypto-js';
|
|
3
|
-
|
|
4
|
-
class Cypher {
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
const self = this;
|
|
8
|
-
self._registerKey = 'kduD^!r8sl5#Vb$OpsD4!xWY8z#QH#WWTc4mNpmzg*TnVnMCZ^';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
get(info) {
|
|
12
|
-
const self = this;
|
|
13
|
-
try {
|
|
14
|
-
const bytes = CryptoJS.AES.decrypt(info, self._registerKey);
|
|
15
|
-
const bias = bytes.toString(CryptoJS.enc.Utf8);
|
|
16
|
-
return JSON.parse(bias);
|
|
17
|
-
} catch (ex) {
|
|
18
|
-
return {};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
set(obj) {
|
|
23
|
-
const self = this;
|
|
24
|
-
let retData;
|
|
25
|
-
try {
|
|
26
|
-
const info = JSON.stringify(obj);
|
|
27
|
-
retData = CryptoJS.AES.encrypt(info, self._registerKey).toString();
|
|
28
|
-
} catch(ex) {
|
|
29
|
-
retData = '';
|
|
30
|
-
} finally {
|
|
31
|
-
return retData;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const cypher = new Cypher();
|
|
37
|
-
export default cypher;
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import CryptoJS from 'crypto-js';
|
|
3
|
+
|
|
4
|
+
class Cypher {
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
const self = this;
|
|
8
|
+
self._registerKey = 'kduD^!r8sl5#Vb$OpsD4!xWY8z#QH#WWTc4mNpmzg*TnVnMCZ^';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get(info) {
|
|
12
|
+
const self = this;
|
|
13
|
+
try {
|
|
14
|
+
const bytes = CryptoJS.AES.decrypt(info, self._registerKey);
|
|
15
|
+
const bias = bytes.toString(CryptoJS.enc.Utf8);
|
|
16
|
+
return JSON.parse(bias);
|
|
17
|
+
} catch (ex) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
set(obj) {
|
|
23
|
+
const self = this;
|
|
24
|
+
let retData;
|
|
25
|
+
try {
|
|
26
|
+
const info = JSON.stringify(obj);
|
|
27
|
+
retData = CryptoJS.AES.encrypt(info, self._registerKey).toString();
|
|
28
|
+
} catch(ex) {
|
|
29
|
+
retData = '';
|
|
30
|
+
} finally {
|
|
31
|
+
return retData;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const cypher = new Cypher();
|
|
37
|
+
export default cypher;
|