@docbrasil/api-systemmanager 1.1.8 → 1.1.10
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/user/index.js +2 -0
- package/api/user/settings.js +142 -0
- package/dist/bundle.cjs +138 -0
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +79 -0
- package/docs/Admin.html +1 -1
- package/docs/AdminDocuments.html +1 -1
- package/docs/AdminForm.html +1 -1
- package/docs/AdminLists.html +1 -1
- package/docs/AdminMessage.html +1 -1
- package/docs/AdminNotification.html +1 -1
- package/docs/AdminPlugin.html +1 -1
- package/docs/AdminPolicy.html +1 -1
- package/docs/AdminProcesses.html +1 -1
- package/docs/AdminTask.html +1 -1
- package/docs/AdminUser.html +1 -1
- package/docs/Application.html +1 -1
- package/docs/Datasource.html +1 -1
- package/docs/Dispatch.html +1 -1
- package/docs/Documents.html +13 -13
- package/docs/External.html +1 -1
- package/docs/GeoLocation.html +1 -1
- package/docs/Help.html +1 -1
- package/docs/Login.html +1 -1
- package/docs/MyTasks.html +1 -1
- package/docs/Notification.html +1 -1
- package/docs/Organization.html +1 -1
- package/docs/Page.html +1 -1
- package/docs/Process.html +1 -1
- package/docs/Register.html +1 -1
- package/docs/Session.html +1 -1
- package/docs/Settings.html +863 -0
- package/docs/Task.html +1 -1
- package/docs/TaskAvailable.html +1 -1
- package/docs/Updates.html +1 -1
- package/docs/User.html +1 -1
- package/docs/Users.html +2 -2
- package/docs/admin_doctypes.js.html +1 -1
- package/docs/admin_document.js.html +1 -1
- package/docs/admin_form.js.html +1 -1
- package/docs/admin_index.js.html +1 -1
- package/docs/admin_list.js.html +1 -1
- package/docs/admin_message.js.html +1 -1
- package/docs/admin_notification.js.html +1 -1
- package/docs/admin_organization.js.html +1 -1
- package/docs/admin_plugin.js.html +1 -1
- package/docs/admin_policy.js.html +1 -1
- package/docs/admin_processes.js.html +1 -1
- package/docs/admin_task.js.html +1 -1
- package/docs/admin_user.js.html +1 -1
- package/docs/dispatch.js.html +1 -1
- package/docs/external.js.html +1 -1
- package/docs/general_geoLocation.js.html +1 -1
- package/docs/general_index.js.html +1 -1
- package/docs/index.html +1 -1
- package/docs/login.js.html +1 -1
- package/docs/session.js.html +1 -1
- package/docs/user_application.js.html +1 -1
- package/docs/user_datasource.js.html +1 -1
- package/docs/user_document.js.html +16 -3
- package/docs/user_help.js.html +1 -1
- package/docs/user_index.js.html +3 -1
- package/docs/user_my_tasks.js.html +1 -1
- package/docs/user_notification.js.html +1 -1
- package/docs/user_organization.js.html +1 -1
- package/docs/user_page.js.html +1 -1
- package/docs/user_process.js.html +1 -1
- package/docs/user_register.js.html +1 -1
- package/docs/user_settings.js.html +259 -0
- package/docs/user_task.js.html +1 -1
- package/docs/user_task_available.js.html +1 -1
- package/docs/user_updates.js.html +1 -1
- package/docs/user_user.js.html +1 -1
- package/docs/utils_promises.js.html +1 -1
- package/package.json +1 -1
- package/tests/documents_002.spec.js +0 -107
package/api/user/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import Updates from './updates.js';
|
|
|
12
12
|
import Help from './help.js';
|
|
13
13
|
import Datasource from './datasource.js';
|
|
14
14
|
import Application from './application.js';
|
|
15
|
+
import Settings from './settings.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* @class API request, user permission level
|
|
@@ -34,6 +35,7 @@ class Users {
|
|
|
34
35
|
self.process = new Process(options);
|
|
35
36
|
self.task = new Task(options);
|
|
36
37
|
self.user = self.profile = new User(options);
|
|
38
|
+
self.settings = new Settings(options);
|
|
37
39
|
self.register = new Register(options);
|
|
38
40
|
self.notification = new Notification(options);
|
|
39
41
|
self.updates = new Updates(options);
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Boom from '@hapi/boom';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Class for user settings
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class Settings {
|
|
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 Adds/updates a user settings
|
|
58
|
+
* @param {object} settings Full user settings
|
|
59
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
60
|
+
* @return {Promise}
|
|
61
|
+
* @public
|
|
62
|
+
* @async
|
|
63
|
+
* @example
|
|
64
|
+
*
|
|
65
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
66
|
+
* const api = new API();
|
|
67
|
+
* const settings = {
|
|
68
|
+
* areaId: '55e4a3bd6be6b45210833fae'
|
|
69
|
+
* };
|
|
70
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
71
|
+
* await api.user.settings.upsert(settings, session);
|
|
72
|
+
*/
|
|
73
|
+
async upsert(settings, session) {
|
|
74
|
+
const self = this;
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
Joi.assert(settings, Joi.object().required());
|
|
78
|
+
Joi.assert(session, Joi.string().required());
|
|
79
|
+
|
|
80
|
+
const apiCall = self._client.put(`/users/settings`, settings, self._setHeader(session));
|
|
81
|
+
return self._returnData(await apiCall);
|
|
82
|
+
} catch (ex) {
|
|
83
|
+
throw ex;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
89
|
+
* @description Gets the user settings. Returns an array of settings.
|
|
90
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
91
|
+
* @return {Promise}
|
|
92
|
+
* @public
|
|
93
|
+
* @async
|
|
94
|
+
* @example
|
|
95
|
+
*
|
|
96
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
97
|
+
* const api = new API();
|
|
98
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
99
|
+
* ret settings = await api.user.settings.get(session);
|
|
100
|
+
*/
|
|
101
|
+
async get(session) {
|
|
102
|
+
const self = this;
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
Joi.assert(session, Joi.string().required());
|
|
106
|
+
|
|
107
|
+
const apiCall = self._client.get(`/users/settings`, self._setHeader(session));
|
|
108
|
+
return self._returnData(await apiCall);
|
|
109
|
+
} catch (ex) {
|
|
110
|
+
throw ex;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
116
|
+
* @description Removes the user settings
|
|
117
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
118
|
+
* @return {Promise}
|
|
119
|
+
* @public
|
|
120
|
+
* @async
|
|
121
|
+
* @example
|
|
122
|
+
*
|
|
123
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
124
|
+
* const api = new API();
|
|
125
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
126
|
+
* await api.user.settings.remove(session);
|
|
127
|
+
*/
|
|
128
|
+
async remove(session) {
|
|
129
|
+
const self = this;
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
Joi.assert(session, Joi.string().required());
|
|
133
|
+
|
|
134
|
+
const apiCall = self._client.del(`/users/settings`, self._setHeader(session));
|
|
135
|
+
return self._returnData(await apiCall);
|
|
136
|
+
} catch (ex) {
|
|
137
|
+
throw ex;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export default Settings;
|
package/dist/bundle.cjs
CHANGED
|
@@ -10361,6 +10361,143 @@ class Application {
|
|
|
10361
10361
|
}
|
|
10362
10362
|
}
|
|
10363
10363
|
|
|
10364
|
+
/**
|
|
10365
|
+
* Class for user settings
|
|
10366
|
+
* @class
|
|
10367
|
+
*/
|
|
10368
|
+
class Settings {
|
|
10369
|
+
|
|
10370
|
+
constructor(options) {
|
|
10371
|
+
Joi__default["default"].assert(options, Joi__default["default"].object().required());
|
|
10372
|
+
Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
|
|
10373
|
+
|
|
10374
|
+
const self = this;
|
|
10375
|
+
self._parent = options.parent;
|
|
10376
|
+
self._client = self._parent.dispatch.getClient();
|
|
10377
|
+
self.gender = {
|
|
10378
|
+
male: 1,
|
|
10379
|
+
female: 2,
|
|
10380
|
+
nonBinary: 3
|
|
10381
|
+
};
|
|
10382
|
+
}
|
|
10383
|
+
|
|
10384
|
+
/**
|
|
10385
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
10386
|
+
* @description Get the return data and check for errors
|
|
10387
|
+
* @param {object} retData Response HTTP
|
|
10388
|
+
* @return {*}
|
|
10389
|
+
* @private
|
|
10390
|
+
*/
|
|
10391
|
+
_returnData(retData, def = {}) {
|
|
10392
|
+
if (retData.status !== 200) {
|
|
10393
|
+
return Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
|
|
10394
|
+
} else {
|
|
10395
|
+
return ___default["default"].get(retData, 'data', def);
|
|
10396
|
+
}
|
|
10397
|
+
}
|
|
10398
|
+
|
|
10399
|
+
/**
|
|
10400
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
10401
|
+
* @description Set header with new session
|
|
10402
|
+
* @param {string} session Session, token JWT
|
|
10403
|
+
* @return {object} header with new session
|
|
10404
|
+
* @private
|
|
10405
|
+
*/
|
|
10406
|
+
_setHeader(session) {
|
|
10407
|
+
return {
|
|
10408
|
+
headers: {
|
|
10409
|
+
authorization: session,
|
|
10410
|
+
}
|
|
10411
|
+
};
|
|
10412
|
+
}
|
|
10413
|
+
|
|
10414
|
+
/**
|
|
10415
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
10416
|
+
* @description Adds/updates a user settings
|
|
10417
|
+
* @param {object} settings Full user settings
|
|
10418
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
10419
|
+
* @return {Promise}
|
|
10420
|
+
* @public
|
|
10421
|
+
* @async
|
|
10422
|
+
* @example
|
|
10423
|
+
*
|
|
10424
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
10425
|
+
* const api = new API();
|
|
10426
|
+
* const settings = {
|
|
10427
|
+
* areaId: '55e4a3bd6be6b45210833fae'
|
|
10428
|
+
* };
|
|
10429
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
10430
|
+
* await api.user.settings.upsert(settings, session);
|
|
10431
|
+
*/
|
|
10432
|
+
async upsert(settings, session) {
|
|
10433
|
+
const self = this;
|
|
10434
|
+
|
|
10435
|
+
try {
|
|
10436
|
+
Joi__default["default"].assert(settings, Joi__default["default"].object().required());
|
|
10437
|
+
Joi__default["default"].assert(session, Joi__default["default"].string().required());
|
|
10438
|
+
|
|
10439
|
+
const apiCall = self._client.put(`/users/settings`, settings, self._setHeader(session));
|
|
10440
|
+
return self._returnData(await apiCall);
|
|
10441
|
+
} catch (ex) {
|
|
10442
|
+
throw ex;
|
|
10443
|
+
}
|
|
10444
|
+
}
|
|
10445
|
+
|
|
10446
|
+
/**
|
|
10447
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
10448
|
+
* @description Gets the user settings. Returns an array of settings.
|
|
10449
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
10450
|
+
* @return {Promise}
|
|
10451
|
+
* @public
|
|
10452
|
+
* @async
|
|
10453
|
+
* @example
|
|
10454
|
+
*
|
|
10455
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
10456
|
+
* const api = new API();
|
|
10457
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
10458
|
+
* ret settings = await api.user.settings.get(session);
|
|
10459
|
+
*/
|
|
10460
|
+
async get(session) {
|
|
10461
|
+
const self = this;
|
|
10462
|
+
|
|
10463
|
+
try {
|
|
10464
|
+
Joi__default["default"].assert(session, Joi__default["default"].string().required());
|
|
10465
|
+
|
|
10466
|
+
const apiCall = self._client.get(`/users/settings`, self._setHeader(session));
|
|
10467
|
+
return self._returnData(await apiCall);
|
|
10468
|
+
} catch (ex) {
|
|
10469
|
+
throw ex;
|
|
10470
|
+
}
|
|
10471
|
+
}
|
|
10472
|
+
|
|
10473
|
+
/**
|
|
10474
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
10475
|
+
* @description Removes the user settings
|
|
10476
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
10477
|
+
* @return {Promise}
|
|
10478
|
+
* @public
|
|
10479
|
+
* @async
|
|
10480
|
+
* @example
|
|
10481
|
+
*
|
|
10482
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
10483
|
+
* const api = new API();
|
|
10484
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
10485
|
+
* await api.user.settings.remove(session);
|
|
10486
|
+
*/
|
|
10487
|
+
async remove(session) {
|
|
10488
|
+
const self = this;
|
|
10489
|
+
|
|
10490
|
+
try {
|
|
10491
|
+
Joi__default["default"].assert(session, Joi__default["default"].string().required());
|
|
10492
|
+
|
|
10493
|
+
const apiCall = self._client.del(`/users/settings`, self._setHeader(session));
|
|
10494
|
+
return self._returnData(await apiCall);
|
|
10495
|
+
} catch (ex) {
|
|
10496
|
+
throw ex;
|
|
10497
|
+
}
|
|
10498
|
+
}
|
|
10499
|
+
}
|
|
10500
|
+
|
|
10364
10501
|
/**
|
|
10365
10502
|
* @class API request, user permission level
|
|
10366
10503
|
*/
|
|
@@ -10382,6 +10519,7 @@ class Users {
|
|
|
10382
10519
|
self.process = new Process(options);
|
|
10383
10520
|
self.task = new Task(options);
|
|
10384
10521
|
self.user = self.profile = new User(options);
|
|
10522
|
+
self.settings = new Settings(options);
|
|
10385
10523
|
self.register = new Register(options);
|
|
10386
10524
|
self.notification = new Notification(options);
|
|
10387
10525
|
self.updates = new Updates(options);
|