@docbrasil/api-systemmanager 1.0.35 → 1.0.39
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 +1 -1
- package/api/admin/document.js +1 -1
- package/api/admin/form.js +1 -1
- package/api/admin/list.js +1 -1
- package/api/admin/message.js +1 -1
- package/api/admin/notification.js +1 -1
- package/api/admin/plugin.js +1 -1
- package/api/admin/policy.js +1 -1
- package/api/admin/processes.js +1 -1
- package/api/admin/task.js +1 -1
- package/api/admin/user.js +1 -1
- package/api/general/geoLocation.js +1 -1
- package/api/session.js +1 -1
- package/api/user/document.js +3 -2
- package/api/user/index.js +1 -1
- package/api/user/organization.js +68 -1
- package/api/user/process.js +1 -1
- package/api/user/register.js +13 -5
- package/api/user/task.js +1 -1
- package/api/user/user.js +68 -3
- package/api/utils/promises.js +1 -1
- package/doc/api.md +98 -5
- package/helper/boom.js +487 -0
- package/package.json +1 -1
package/api/admin/doctypes.js
CHANGED
package/api/admin/document.js
CHANGED
package/api/admin/form.js
CHANGED
package/api/admin/list.js
CHANGED
package/api/admin/message.js
CHANGED
package/api/admin/plugin.js
CHANGED
package/api/admin/policy.js
CHANGED
package/api/admin/processes.js
CHANGED
package/api/admin/task.js
CHANGED
package/api/admin/user.js
CHANGED
package/api/session.js
CHANGED
package/api/user/document.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
|
-
const Boom = require('
|
|
2
|
+
const Boom = require('../../helper/boom');
|
|
3
3
|
const Joi = require('joi');
|
|
4
4
|
const Moment = require('moment');
|
|
5
5
|
|
|
@@ -84,7 +84,7 @@ class Documents {
|
|
|
84
84
|
areaId: _.get(params, 'areaId'),
|
|
85
85
|
docId: _.get(params, 'docId'),
|
|
86
86
|
documentDate: _.get(params, 'documentDate', Moment().format()),
|
|
87
|
-
document: _.get(params, '
|
|
87
|
+
document: _.get(params, 'document'),
|
|
88
88
|
type: _.get(params, 'type'),
|
|
89
89
|
name: _.get(params, 'name'),
|
|
90
90
|
content: _.get(params, 'content', ''),
|
|
@@ -140,6 +140,7 @@ class Documents {
|
|
|
140
140
|
* @param {string} params.areaId Doc area id (_id database)
|
|
141
141
|
* @param {string} params.docId Document id (_id database)
|
|
142
142
|
* @param {string} [params.documentDate=new\ Date()] Date of document
|
|
143
|
+
* @param {string} params.document The path to the file. If S3, the key to S3, gotten after getting a signed URL
|
|
143
144
|
* @param {string} params.filename File name
|
|
144
145
|
* @param {string} params.type Mimetype of the document (image/png)
|
|
145
146
|
* @param {string} params.name Document name
|
package/api/user/index.js
CHANGED
|
@@ -27,7 +27,7 @@ class Users {
|
|
|
27
27
|
self.organization = new Organization(options);
|
|
28
28
|
self.process = new Process(options);
|
|
29
29
|
self.task = new Task(options);
|
|
30
|
-
self.user = new User(options);
|
|
30
|
+
self.user = self.profile = new User(options);
|
|
31
31
|
self.register = new Register(options);
|
|
32
32
|
}
|
|
33
33
|
}
|
package/api/user/organization.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
|
-
const Boom = require('
|
|
2
|
+
const Boom = require('../../helper/boom');
|
|
3
3
|
const Joi = require('joi');
|
|
4
4
|
const Axios = require('axios');
|
|
5
5
|
|
|
@@ -106,6 +106,73 @@ class Organization {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
111
|
+
* @description Update avatar of organization by session of user not allow session user SU
|
|
112
|
+
* @param {object} params Params to update avatar
|
|
113
|
+
* @param {string} params.avatar Image in base64 to update
|
|
114
|
+
* @param {string} params.type mimeType (image/png)
|
|
115
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
116
|
+
* @return {Promise}
|
|
117
|
+
* @public
|
|
118
|
+
* @async
|
|
119
|
+
* @example
|
|
120
|
+
*
|
|
121
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
122
|
+
* const api = new API();
|
|
123
|
+
* const params = {
|
|
124
|
+
* avatar: 'iVBORw0KGgoAAAANSUhEUgAAAasAAAHnCAYAAAAGi3J6AAA9BElEQVR...He3/kk/m7kl35S8AAAAASUVORK5CYII=',
|
|
125
|
+
* type: 'image/png',
|
|
126
|
+
* };
|
|
127
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
128
|
+
* await api.user.profile.updateAvatar(params, session);
|
|
129
|
+
*/
|
|
130
|
+
async upsertAvatar(params = {}, session) {
|
|
131
|
+
const self = this;
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
Joi.assert(params, Joi.object().required());
|
|
135
|
+
Joi.assert(params.avatar, Joi.string().required());
|
|
136
|
+
Joi.assert(params.type, Joi.string().required());
|
|
137
|
+
Joi.assert(session, Joi.string().required());
|
|
138
|
+
|
|
139
|
+
const {avatar, type} = params;
|
|
140
|
+
const payload = {avatar, type};
|
|
141
|
+
|
|
142
|
+
const apiCall = self._client.put('/organizations/1234567890/logo', payload, 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 Remove avatar of user by session of user not allow session user SU
|
|
152
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
153
|
+
* @return {Promise}
|
|
154
|
+
* @public
|
|
155
|
+
* @async
|
|
156
|
+
* @example
|
|
157
|
+
*
|
|
158
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
159
|
+
* const api = new API();
|
|
160
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
161
|
+
* await api.user.profile.removeAvatar(session);
|
|
162
|
+
*/
|
|
163
|
+
async removeAvatar(session) {
|
|
164
|
+
const self = this;
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
Joi.assert(session, Joi.string().required());
|
|
168
|
+
|
|
169
|
+
const apiCall = self._client.delete('/organizations/1234567890/logo', self._setHeader(session));
|
|
170
|
+
return self._returnData(await apiCall);
|
|
171
|
+
} catch (ex) {
|
|
172
|
+
throw ex;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
109
176
|
/**
|
|
110
177
|
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
111
178
|
* @description Call URL internal
|
package/api/user/process.js
CHANGED
package/api/user/register.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
|
-
const Boom = require('
|
|
2
|
+
const Boom = require('../../helper/boom');
|
|
3
3
|
const Joi = require('joi');
|
|
4
4
|
const Cypher = require('../utils/cypher');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Class for user registration in a
|
|
7
|
+
* Class for user registration in a user
|
|
8
8
|
* @class
|
|
9
9
|
*/
|
|
10
10
|
class Register {
|
|
@@ -120,9 +120,10 @@ class Register {
|
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
123
|
-
* @description Method to
|
|
123
|
+
* @description Method to register a user
|
|
124
124
|
* @param {object} params Params to get task
|
|
125
125
|
* @param {string} params.registerId The registerId that comes with the registration page context
|
|
126
|
+
* @param {string} params.type=sign The type of the registration. By defailt,
|
|
126
127
|
* @param {boolean} params.login=false If we want to login the user directly after registering the user successfully. If you have a redirect, the best option is to login automatically.
|
|
127
128
|
* @param {object} params.emailInfo The information for the email validation
|
|
128
129
|
* @param {string} params.emailInfo.email The email validation information
|
|
@@ -149,6 +150,7 @@ class Register {
|
|
|
149
150
|
* const api = new API();
|
|
150
151
|
* const params ={
|
|
151
152
|
* "registerId": 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...',
|
|
153
|
+
* "type": 'sign',
|
|
152
154
|
* "login": false,
|
|
153
155
|
* "emailInfo": {
|
|
154
156
|
* "code": "5974",
|
|
@@ -178,9 +180,15 @@ class Register {
|
|
|
178
180
|
Joi.assert(params.emailInfo, Joi.object().required(), ' The email info');
|
|
179
181
|
Joi.assert(params.registerData, Joi.object().required(), ' The registerData');
|
|
180
182
|
|
|
181
|
-
const {
|
|
183
|
+
const {
|
|
184
|
+
type = 'sign',
|
|
185
|
+
registerId = '',
|
|
186
|
+
emailInfo = {},
|
|
187
|
+
registerData = {},
|
|
188
|
+
login = false
|
|
189
|
+
} = params;
|
|
182
190
|
const registerInfo = Cypher.get(registerId) || {};
|
|
183
|
-
const payload = { ...registerInfo, login, emailInfo, registerData };
|
|
191
|
+
const payload = { ...registerInfo, type, login, emailInfo, registerData };
|
|
184
192
|
const payloadInfo = { info: Cypher.set(payload) };
|
|
185
193
|
const apiCall = self._client
|
|
186
194
|
.put(`/users/register`, payloadInfo);
|
package/api/user/task.js
CHANGED
package/api/user/user.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
|
-
const Boom = require('
|
|
2
|
+
const Boom = require('../../helper/boom');
|
|
3
3
|
const Joi = require('joi');
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -15,6 +15,11 @@ class User {
|
|
|
15
15
|
const self = this;
|
|
16
16
|
self._parent = options.parent;
|
|
17
17
|
self._client = self._parent.dispatch.getClient();
|
|
18
|
+
self.gender = {
|
|
19
|
+
male: 1,
|
|
20
|
+
female: 2,
|
|
21
|
+
nonBinary: 3
|
|
22
|
+
};
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
/**
|
|
@@ -66,7 +71,7 @@ class User {
|
|
|
66
71
|
* type: '123456',
|
|
67
72
|
* };
|
|
68
73
|
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
69
|
-
* await api.user.
|
|
74
|
+
* await api.user.profile.updateAvatar(params, session);
|
|
70
75
|
*/
|
|
71
76
|
async updateAvatar(params, session) {
|
|
72
77
|
const self = this;
|
|
@@ -99,7 +104,7 @@ class User {
|
|
|
99
104
|
* const API = require('@docbrasil/api-systemmanager');
|
|
100
105
|
* const api = new API();
|
|
101
106
|
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
102
|
-
* await api.user.
|
|
107
|
+
* await api.user.profile.removeAvatar(session);
|
|
103
108
|
*/
|
|
104
109
|
async removeAvatar(session) {
|
|
105
110
|
const self = this;
|
|
@@ -113,6 +118,66 @@ class User {
|
|
|
113
118
|
throw ex;
|
|
114
119
|
}
|
|
115
120
|
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
124
|
+
* @description Update a user profile by id
|
|
125
|
+
* @param {object} params Params to update task
|
|
126
|
+
* @param {string} params.name The name of the user
|
|
127
|
+
* @param {string} params.site The site of the user
|
|
128
|
+
* @param {string} params.faceboook The faceboook of the user
|
|
129
|
+
* @param {string} params.linkedin The linkedin of the user
|
|
130
|
+
* @param {date} params.dob The date of birth of the user
|
|
131
|
+
* @param {number<UserGender>} params.gender The gender of of the user self.gender
|
|
132
|
+
* @param {string} params.phone The phone
|
|
133
|
+
* @param {string} params.phone2 The phone 2
|
|
134
|
+
* @param {string} params.phone3 The phone 3
|
|
135
|
+
* @param {string} params.password The password to change
|
|
136
|
+
* @param {string} params.secQuestion The security question
|
|
137
|
+
* @param {string} params.secAnswer The security answer
|
|
138
|
+
* @param {string} params.timezone The timezone
|
|
139
|
+
* @param {string} params.userLanguage The user language
|
|
140
|
+
* @param {string} params.changePassword (required) If we need to change the status and we changed the password
|
|
141
|
+
* @param {string} params.acceptTermsOfUse If the user has accepted the terms of change
|
|
142
|
+
* @param {string} session Session, token JWT
|
|
143
|
+
* @return {Promise<void>}
|
|
144
|
+
* @public
|
|
145
|
+
* @async
|
|
146
|
+
* @example
|
|
147
|
+
*
|
|
148
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
149
|
+
* const api = new API();
|
|
150
|
+
* const params = {
|
|
151
|
+
* name: 'New Name'
|
|
152
|
+
* };
|
|
153
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
154
|
+
* await api.user.profile.findByIdAndUpdate(params, session);
|
|
155
|
+
*/
|
|
156
|
+
async findByIdAndUpdate(params = {}, session) {
|
|
157
|
+
const self = this;
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
Joi.assert(session, Joi.string().required());
|
|
161
|
+
Joi.assert(params, Joi.object().required());
|
|
162
|
+
Joi.assert(params.changePassword, Joi.boolean().required());
|
|
163
|
+
|
|
164
|
+
if(_.isEmpty(params)) return;
|
|
165
|
+
|
|
166
|
+
const { changePassword = false, password = '' } = params;
|
|
167
|
+
|
|
168
|
+
if(changePassword && password === '') {
|
|
169
|
+
throw new Error('It is required to change the password')
|
|
170
|
+
} else {
|
|
171
|
+
params.changePassword = false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const url = 'users';
|
|
175
|
+
const apiCall = self._client.put(url, params, self._setHeader(session));
|
|
176
|
+
return self._returnData(await apiCall);
|
|
177
|
+
} catch (ex) {
|
|
178
|
+
throw ex;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
116
181
|
}
|
|
117
182
|
|
|
118
183
|
module.exports = User;
|
package/api/utils/promises.js
CHANGED
package/doc/api.md
CHANGED
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
<dd><p>Class for process, permission user</p>
|
|
54
54
|
</dd>
|
|
55
55
|
<dt><a href="#Register">Register</a></dt>
|
|
56
|
-
<dd><p>Class for user registration in a
|
|
56
|
+
<dd><p>Class for user registration in a user</p>
|
|
57
57
|
</dd>
|
|
58
58
|
<dt><a href="#Task">Task</a></dt>
|
|
59
59
|
<dd><p>Class for task, permission user</p>
|
|
@@ -996,6 +996,7 @@ Create new document
|
|
|
996
996
|
| params.areaId | <code>string</code> | | Doc area id (_id database) |
|
|
997
997
|
| params.docId | <code>string</code> | | Document id (_id database) |
|
|
998
998
|
| [params.documentDate] | <code>string</code> | <code>"new\\ Date()"</code> | Date of document |
|
|
999
|
+
| params.document | <code>string</code> | | The path to the file. If S3, the key to S3, gotten after getting a signed URL |
|
|
999
1000
|
| params.filename | <code>string</code> | | File name |
|
|
1000
1001
|
| params.type | <code>string</code> | | Mimetype of the document (image/png) |
|
|
1001
1002
|
| params.name | <code>string</code> | | Document name |
|
|
@@ -1249,6 +1250,8 @@ Class for organizations, permission user
|
|
|
1249
1250
|
* [Organization](#Organization)
|
|
1250
1251
|
* [.findById(orgId, session)](#Organization+findById)
|
|
1251
1252
|
* [.idCardExist(idcard, session)](#Organization+idCardExist)
|
|
1253
|
+
* [.upsertAvatar(params, session)](#Organization+upsertAvatar) ⇒ <code>Promise</code>
|
|
1254
|
+
* [.removeAvatar(session)](#Organization+removeAvatar) ⇒ <code>Promise</code>
|
|
1252
1255
|
* [.callFetch(params, params)](#Organization+callFetch) ⇒ <code>promise</code> \| <code>promise</code>
|
|
1253
1256
|
|
|
1254
1257
|
<a name="Organization+findById"></a>
|
|
@@ -1295,6 +1298,53 @@ const idCard = '80443245000122';
|
|
|
1295
1298
|
const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
1296
1299
|
await api.user.organization.idCardExist(idCard, session);
|
|
1297
1300
|
```
|
|
1301
|
+
<a name="Organization+upsertAvatar"></a>
|
|
1302
|
+
|
|
1303
|
+
### organization.upsertAvatar(params, session) ⇒ <code>Promise</code>
|
|
1304
|
+
Update avatar of organization by session of user not allow session user SU
|
|
1305
|
+
|
|
1306
|
+
**Kind**: instance method of [<code>Organization</code>](#Organization)
|
|
1307
|
+
**Access**: public
|
|
1308
|
+
**Author**: CloudBrasil <abernardo.br@gmail.com>
|
|
1309
|
+
|
|
1310
|
+
| Param | Type | Description |
|
|
1311
|
+
| --- | --- | --- |
|
|
1312
|
+
| params | <code>object</code> | Params to update avatar |
|
|
1313
|
+
| params.avatar | <code>string</code> | Image in base64 to update |
|
|
1314
|
+
| params.type | <code>string</code> | mimeType (image/png) |
|
|
1315
|
+
| session | <code>string</code> | Is token JWT of user NOT allow SU |
|
|
1316
|
+
|
|
1317
|
+
**Example**
|
|
1318
|
+
```js
|
|
1319
|
+
const API = require('@docbrasil/api-systemmanager');
|
|
1320
|
+
const api = new API();
|
|
1321
|
+
const params = {
|
|
1322
|
+
avatar: 'iVBORw0KGgoAAAANSUhEUgAAAasAAAHnCAYAAAAGi3J6AAA9BElEQVR...He3/kk/m7kl35S8AAAAASUVORK5CYII=',
|
|
1323
|
+
type: 'image/png',
|
|
1324
|
+
};
|
|
1325
|
+
const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
1326
|
+
await api.user.profile.updateAvatar(params, session);
|
|
1327
|
+
```
|
|
1328
|
+
<a name="Organization+removeAvatar"></a>
|
|
1329
|
+
|
|
1330
|
+
### organization.removeAvatar(session) ⇒ <code>Promise</code>
|
|
1331
|
+
Remove avatar of user by session of user not allow session user SU
|
|
1332
|
+
|
|
1333
|
+
**Kind**: instance method of [<code>Organization</code>](#Organization)
|
|
1334
|
+
**Access**: public
|
|
1335
|
+
**Author**: CloudBrasil <abernardo.br@gmail.com>
|
|
1336
|
+
|
|
1337
|
+
| Param | Type | Description |
|
|
1338
|
+
| --- | --- | --- |
|
|
1339
|
+
| session | <code>string</code> | Is token JWT of user NOT allow SU |
|
|
1340
|
+
|
|
1341
|
+
**Example**
|
|
1342
|
+
```js
|
|
1343
|
+
const API = require('@docbrasil/api-systemmanager');
|
|
1344
|
+
const api = new API();
|
|
1345
|
+
const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
1346
|
+
await api.user.profile.removeAvatar(session);
|
|
1347
|
+
```
|
|
1298
1348
|
<a name="Organization+callFetch"></a>
|
|
1299
1349
|
|
|
1300
1350
|
### organization.callFetch(params, params) ⇒ <code>promise</code> \| <code>promise</code>
|
|
@@ -1397,7 +1447,7 @@ await api.user.process.getProcessProperties(params, session);
|
|
|
1397
1447
|
<a name="Register"></a>
|
|
1398
1448
|
|
|
1399
1449
|
## Register
|
|
1400
|
-
Class for user registration in a
|
|
1450
|
+
Class for user registration in a user
|
|
1401
1451
|
|
|
1402
1452
|
**Kind**: global class
|
|
1403
1453
|
|
|
@@ -1456,7 +1506,7 @@ const retData = await api.user.register.validateEmail(params);
|
|
|
1456
1506
|
<a name="Register+execute"></a>
|
|
1457
1507
|
|
|
1458
1508
|
### register.execute(params) ⇒ <code>promise.<object></code> \| <code>boolean</code> \| <code>boolean</code> \| <code>object</code> \| <code>string</code>
|
|
1459
|
-
Method to
|
|
1509
|
+
Method to register a user
|
|
1460
1510
|
|
|
1461
1511
|
**Kind**: instance method of [<code>Register</code>](#Register)
|
|
1462
1512
|
**Returns**: <code>promise.<object></code> - data<code>boolean</code> - data.success If the operation was successfully done (true|false)<code>boolean</code> - data.userAlreadyExists If the user already exists (true|false), if true, then the other information is not returned<code>object</code> - auth The full authentication data with session, if login is true.<code>string</code> - auth.redirectUrl The url to redirect.
|
|
@@ -1467,6 +1517,7 @@ Method to find task by id
|
|
|
1467
1517
|
| --- | --- | --- | --- |
|
|
1468
1518
|
| params | <code>object</code> | | Params to get task |
|
|
1469
1519
|
| params.registerId | <code>string</code> | | The registerId that comes with the registration page context |
|
|
1520
|
+
| params.type | <code>string</code> | <code>"sign"</code> | The type of the registration. By defailt, |
|
|
1470
1521
|
| params.login | <code>boolean</code> | <code>false</code> | If we want to login the user directly after registering the user successfully. If you have a redirect, the best option is to login automatically. |
|
|
1471
1522
|
| params.emailInfo | <code>object</code> | | The information for the email validation |
|
|
1472
1523
|
| params.emailInfo.email | <code>string</code> | | The email validation information |
|
|
@@ -1488,6 +1539,7 @@ const API = require('@docbrasil/api-systemmanager');
|
|
|
1488
1539
|
const api = new API();
|
|
1489
1540
|
const params ={
|
|
1490
1541
|
"registerId": 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...',
|
|
1542
|
+
"type": 'sign',
|
|
1491
1543
|
"login": false,
|
|
1492
1544
|
"emailInfo": {
|
|
1493
1545
|
"code": "5974",
|
|
@@ -1626,6 +1678,7 @@ Class for user, permission user
|
|
|
1626
1678
|
* [User](#User)
|
|
1627
1679
|
* [.updateAvatar(params, session)](#User+updateAvatar) ⇒ <code>Promise</code>
|
|
1628
1680
|
* [.removeAvatar(session)](#User+removeAvatar) ⇒ <code>Promise</code>
|
|
1681
|
+
* [.findByIdAndUpdate(params, session)](#User+findByIdAndUpdate) ⇒ <code>Promise.<void></code>
|
|
1629
1682
|
|
|
1630
1683
|
<a name="User+updateAvatar"></a>
|
|
1631
1684
|
|
|
@@ -1652,7 +1705,7 @@ const params = {
|
|
|
1652
1705
|
type: '123456',
|
|
1653
1706
|
};
|
|
1654
1707
|
const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
1655
|
-
await api.user.
|
|
1708
|
+
await api.user.profile.updateAvatar(params, session);
|
|
1656
1709
|
```
|
|
1657
1710
|
<a name="User+removeAvatar"></a>
|
|
1658
1711
|
|
|
@@ -1672,5 +1725,45 @@ Remove avatar of user by session of user not allow session user SU
|
|
|
1672
1725
|
const API = require('@docbrasil/api-systemmanager');
|
|
1673
1726
|
const api = new API();
|
|
1674
1727
|
const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
1675
|
-
await api.user.
|
|
1728
|
+
await api.user.profile.removeAvatar(session);
|
|
1729
|
+
```
|
|
1730
|
+
<a name="User+findByIdAndUpdate"></a>
|
|
1731
|
+
|
|
1732
|
+
### user.findByIdAndUpdate(params, session) ⇒ <code>Promise.<void></code>
|
|
1733
|
+
Update a user profile by id
|
|
1734
|
+
|
|
1735
|
+
**Kind**: instance method of [<code>User</code>](#User)
|
|
1736
|
+
**Access**: public
|
|
1737
|
+
**Author**: CloudBrasil <abernardo.br@gmail.com>
|
|
1738
|
+
|
|
1739
|
+
| Param | Type | Description |
|
|
1740
|
+
| --- | --- | --- |
|
|
1741
|
+
| params | <code>object</code> | Params to update task |
|
|
1742
|
+
| params.name | <code>string</code> | The name of the user |
|
|
1743
|
+
| params.site | <code>string</code> | The site of the user |
|
|
1744
|
+
| params.faceboook | <code>string</code> | The faceboook of the user |
|
|
1745
|
+
| params.linkedin | <code>string</code> | The linkedin of the user |
|
|
1746
|
+
| params.dob | <code>date</code> | The date of birth of the user |
|
|
1747
|
+
| params.gender | <code>number.<UserGender></code> | The gender of of the user self.gender |
|
|
1748
|
+
| params.phone | <code>string</code> | The phone |
|
|
1749
|
+
| params.phone2 | <code>string</code> | The phone 2 |
|
|
1750
|
+
| params.phone3 | <code>string</code> | The phone 3 |
|
|
1751
|
+
| params.password | <code>string</code> | The password to change |
|
|
1752
|
+
| params.secQuestion | <code>string</code> | The security question |
|
|
1753
|
+
| params.secAnswer | <code>string</code> | The security answer |
|
|
1754
|
+
| params.timezone | <code>string</code> | The timezone |
|
|
1755
|
+
| params.userLanguage | <code>string</code> | The user language |
|
|
1756
|
+
| params.changePassword | <code>string</code> | If we need to change the status and we changed the password |
|
|
1757
|
+
| params.acceptTermsOfUse | <code>string</code> | If the user has accepted the terms of change |
|
|
1758
|
+
| session | <code>string</code> | Session, token JWT |
|
|
1759
|
+
|
|
1760
|
+
**Example**
|
|
1761
|
+
```js
|
|
1762
|
+
const API = require('@docbrasil/api-systemmanager');
|
|
1763
|
+
const api = new API();
|
|
1764
|
+
const params = {
|
|
1765
|
+
name: 'New Name'
|
|
1766
|
+
};
|
|
1767
|
+
const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
1768
|
+
await api.user.profile.findByIdAndUpdate(params, session);
|
|
1676
1769
|
```
|
package/helper/boom.js
ADDED
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
const _ = require('lodash');
|
|
2
|
+
|
|
3
|
+
const Hoek = {
|
|
4
|
+
clone: message => _.clone(message),
|
|
5
|
+
assert: (condition, ...args) => {
|
|
6
|
+
if (condition) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (args.length === 1 &&
|
|
11
|
+
args[0] instanceof Error) {
|
|
12
|
+
|
|
13
|
+
throw args[0];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
throw new Error(args);
|
|
17
|
+
},
|
|
18
|
+
escapeHeaderAttribute: attribute => {
|
|
19
|
+
return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const internals = {
|
|
25
|
+
codes: new Map([
|
|
26
|
+
[100, 'Continue'],
|
|
27
|
+
[101, 'Switching Protocols'],
|
|
28
|
+
[102, 'Processing'],
|
|
29
|
+
[200, 'OK'],
|
|
30
|
+
[201, 'Created'],
|
|
31
|
+
[202, 'Accepted'],
|
|
32
|
+
[203, 'Non-Authoritative Information'],
|
|
33
|
+
[204, 'No Content'],
|
|
34
|
+
[205, 'Reset Content'],
|
|
35
|
+
[206, 'Partial Content'],
|
|
36
|
+
[207, 'Multi-Status'],
|
|
37
|
+
[300, 'Multiple Choices'],
|
|
38
|
+
[301, 'Moved Permanently'],
|
|
39
|
+
[302, 'Moved Temporarily'],
|
|
40
|
+
[303, 'See Other'],
|
|
41
|
+
[304, 'Not Modified'],
|
|
42
|
+
[305, 'Use Proxy'],
|
|
43
|
+
[307, 'Temporary Redirect'],
|
|
44
|
+
[400, 'Bad Request'],
|
|
45
|
+
[401, 'Unauthorized'],
|
|
46
|
+
[402, 'Payment Required'],
|
|
47
|
+
[403, 'Forbidden'],
|
|
48
|
+
[404, 'Not Found'],
|
|
49
|
+
[405, 'Method Not Allowed'],
|
|
50
|
+
[406, 'Not Acceptable'],
|
|
51
|
+
[407, 'Proxy Authentication Required'],
|
|
52
|
+
[408, 'Request Time-out'],
|
|
53
|
+
[409, 'Conflict'],
|
|
54
|
+
[410, 'Gone'],
|
|
55
|
+
[411, 'Length Required'],
|
|
56
|
+
[412, 'Precondition Failed'],
|
|
57
|
+
[413, 'Request Entity Too Large'],
|
|
58
|
+
[414, 'Request-URI Too Large'],
|
|
59
|
+
[415, 'Unsupported Media Type'],
|
|
60
|
+
[416, 'Requested Range Not Satisfiable'],
|
|
61
|
+
[417, 'Expectation Failed'],
|
|
62
|
+
[418, 'I\'m a teapot'],
|
|
63
|
+
[422, 'Unprocessable Entity'],
|
|
64
|
+
[423, 'Locked'],
|
|
65
|
+
[424, 'Failed Dependency'],
|
|
66
|
+
[425, 'Too Early'],
|
|
67
|
+
[426, 'Upgrade Required'],
|
|
68
|
+
[428, 'Precondition Required'],
|
|
69
|
+
[429, 'Too Many Requests'],
|
|
70
|
+
[431, 'Request Header Fields Too Large'],
|
|
71
|
+
[451, 'Unavailable For Legal Reasons'],
|
|
72
|
+
[500, 'Internal Server Error'],
|
|
73
|
+
[501, 'Not Implemented'],
|
|
74
|
+
[502, 'Bad Gateway'],
|
|
75
|
+
[503, 'Service Unavailable'],
|
|
76
|
+
[504, 'Gateway Time-out'],
|
|
77
|
+
[505, 'HTTP Version Not Supported'],
|
|
78
|
+
[506, 'Variant Also Negotiates'],
|
|
79
|
+
[507, 'Insufficient Storage'],
|
|
80
|
+
[509, 'Bandwidth Limit Exceeded'],
|
|
81
|
+
[510, 'Not Extended'],
|
|
82
|
+
[511, 'Network Authentication Required']
|
|
83
|
+
])
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
exports.Boom = class extends Error {
|
|
88
|
+
|
|
89
|
+
constructor(message, options = {}) {
|
|
90
|
+
|
|
91
|
+
if (message instanceof Error) {
|
|
92
|
+
return exports.boomify(Hoek.clone(message), options);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { statusCode = 500, data = null, ctor = exports.Boom } = options;
|
|
96
|
+
const error = new Error(message ? message : undefined); // Avoids settings null message
|
|
97
|
+
Error.captureStackTrace(error, ctor); // Filter the stack to our external API
|
|
98
|
+
error.data = data;
|
|
99
|
+
const boom = internals.initialize(error, statusCode);
|
|
100
|
+
|
|
101
|
+
Object.defineProperty(boom, 'typeof', { value: ctor });
|
|
102
|
+
|
|
103
|
+
if (options.decorate) {
|
|
104
|
+
Object.assign(boom, options.decorate);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return boom;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static [Symbol.hasInstance](instance) {
|
|
111
|
+
|
|
112
|
+
if (this === exports.Boom) {
|
|
113
|
+
return exports.isBoom(instance);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Cannot use 'instanceof' as it creates infinite recursion
|
|
117
|
+
|
|
118
|
+
return this.prototype.isPrototypeOf(instance);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
exports.isBoom = function (err, statusCode) {
|
|
124
|
+
|
|
125
|
+
return err instanceof Error && !!err.isBoom && (!statusCode || err.output.statusCode === statusCode);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
exports.boomify = function (err, options) {
|
|
130
|
+
|
|
131
|
+
Hoek.assert(err instanceof Error, 'Cannot wrap non-Error object');
|
|
132
|
+
|
|
133
|
+
options = options || {};
|
|
134
|
+
|
|
135
|
+
if (options.data !== undefined) {
|
|
136
|
+
err.data = options.data;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (options.decorate) {
|
|
140
|
+
Object.assign(err, options.decorate);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!err.isBoom) {
|
|
144
|
+
return internals.initialize(err, options.statusCode || 500, options.message);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (options.override === false || // Defaults to true
|
|
148
|
+
!options.statusCode && !options.message) {
|
|
149
|
+
|
|
150
|
+
return err;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return internals.initialize(err, options.statusCode || err.output.statusCode, options.message);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
// 4xx Client Errors
|
|
158
|
+
|
|
159
|
+
exports.badRequest = function (message, data) {
|
|
160
|
+
|
|
161
|
+
return new exports.Boom(message, { statusCode: 400, data, ctor: exports.badRequest });
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
exports.unauthorized = function (message, scheme, attributes) { // Or (message, wwwAuthenticate[])
|
|
166
|
+
|
|
167
|
+
const err = new exports.Boom(message, { statusCode: 401, ctor: exports.unauthorized });
|
|
168
|
+
|
|
169
|
+
// function (message)
|
|
170
|
+
|
|
171
|
+
if (!scheme) {
|
|
172
|
+
return err;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// function (message, wwwAuthenticate[])
|
|
176
|
+
|
|
177
|
+
if (typeof scheme !== 'string') {
|
|
178
|
+
err.output.headers['WWW-Authenticate'] = scheme.join(', ');
|
|
179
|
+
return err;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// function (message, scheme, attributes)
|
|
183
|
+
|
|
184
|
+
let wwwAuthenticate = `${scheme}`;
|
|
185
|
+
|
|
186
|
+
if (attributes ||
|
|
187
|
+
message) {
|
|
188
|
+
|
|
189
|
+
err.output.payload.attributes = {};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (attributes) {
|
|
193
|
+
if (typeof attributes === 'string') {
|
|
194
|
+
wwwAuthenticate += ' ' + Hoek.escapeHeaderAttribute(attributes);
|
|
195
|
+
err.output.payload.attributes = attributes;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
wwwAuthenticate += ' ' + Object.keys(attributes).map((name) => {
|
|
199
|
+
|
|
200
|
+
let value = attributes[name];
|
|
201
|
+
if (value === null ||
|
|
202
|
+
value === undefined) {
|
|
203
|
+
|
|
204
|
+
value = '';
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
err.output.payload.attributes[name] = value;
|
|
208
|
+
return `${name}="${Hoek.escapeHeaderAttribute(value.toString())}"`;
|
|
209
|
+
})
|
|
210
|
+
.join(', ');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (message) {
|
|
215
|
+
if (attributes) {
|
|
216
|
+
wwwAuthenticate += ',';
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
wwwAuthenticate += ` error="${Hoek.escapeHeaderAttribute(message)}"`;
|
|
220
|
+
err.output.payload.attributes.error = message;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
err.isMissing = true;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
err.output.headers['WWW-Authenticate'] = wwwAuthenticate;
|
|
227
|
+
return err;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
exports.paymentRequired = function (message, data) {
|
|
232
|
+
|
|
233
|
+
return new exports.Boom(message, { statusCode: 402, data, ctor: exports.paymentRequired });
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
exports.forbidden = function (message, data) {
|
|
238
|
+
|
|
239
|
+
return new exports.Boom(message, { statusCode: 403, data, ctor: exports.forbidden });
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
exports.notFound = function (message, data) {
|
|
244
|
+
|
|
245
|
+
return new exports.Boom(message, { statusCode: 404, data, ctor: exports.notFound });
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
exports.methodNotAllowed = function (message, data, allow) {
|
|
250
|
+
|
|
251
|
+
const err = new exports.Boom(message, { statusCode: 405, data, ctor: exports.methodNotAllowed });
|
|
252
|
+
|
|
253
|
+
if (typeof allow === 'string') {
|
|
254
|
+
allow = [allow];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (Array.isArray(allow)) {
|
|
258
|
+
err.output.headers.Allow = allow.join(', ');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return err;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
exports.notAcceptable = function (message, data) {
|
|
266
|
+
|
|
267
|
+
return new exports.Boom(message, { statusCode: 406, data, ctor: exports.notAcceptable });
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
exports.proxyAuthRequired = function (message, data) {
|
|
272
|
+
|
|
273
|
+
return new exports.Boom(message, { statusCode: 407, data, ctor: exports.proxyAuthRequired });
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
exports.clientTimeout = function (message, data) {
|
|
278
|
+
|
|
279
|
+
return new exports.Boom(message, { statusCode: 408, data, ctor: exports.clientTimeout });
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
exports.conflict = function (message, data) {
|
|
284
|
+
|
|
285
|
+
return new exports.Boom(message, { statusCode: 409, data, ctor: exports.conflict });
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
exports.resourceGone = function (message, data) {
|
|
290
|
+
|
|
291
|
+
return new exports.Boom(message, { statusCode: 410, data, ctor: exports.resourceGone });
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
exports.lengthRequired = function (message, data) {
|
|
296
|
+
|
|
297
|
+
return new exports.Boom(message, { statusCode: 411, data, ctor: exports.lengthRequired });
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
exports.preconditionFailed = function (message, data) {
|
|
302
|
+
|
|
303
|
+
return new exports.Boom(message, { statusCode: 412, data, ctor: exports.preconditionFailed });
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
exports.entityTooLarge = function (message, data) {
|
|
308
|
+
|
|
309
|
+
return new exports.Boom(message, { statusCode: 413, data, ctor: exports.entityTooLarge });
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
exports.uriTooLong = function (message, data) {
|
|
314
|
+
|
|
315
|
+
return new exports.Boom(message, { statusCode: 414, data, ctor: exports.uriTooLong });
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
exports.unsupportedMediaType = function (message, data) {
|
|
320
|
+
|
|
321
|
+
return new exports.Boom(message, { statusCode: 415, data, ctor: exports.unsupportedMediaType });
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
exports.rangeNotSatisfiable = function (message, data) {
|
|
326
|
+
|
|
327
|
+
return new exports.Boom(message, { statusCode: 416, data, ctor: exports.rangeNotSatisfiable });
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
exports.expectationFailed = function (message, data) {
|
|
332
|
+
|
|
333
|
+
return new exports.Boom(message, { statusCode: 417, data, ctor: exports.expectationFailed });
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
exports.teapot = function (message, data) {
|
|
338
|
+
|
|
339
|
+
return new exports.Boom(message, { statusCode: 418, data, ctor: exports.teapot });
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
exports.badData = function (message, data) {
|
|
344
|
+
|
|
345
|
+
return new exports.Boom(message, { statusCode: 422, data, ctor: exports.badData });
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
exports.locked = function (message, data) {
|
|
350
|
+
|
|
351
|
+
return new exports.Boom(message, { statusCode: 423, data, ctor: exports.locked });
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
exports.failedDependency = function (message, data) {
|
|
356
|
+
|
|
357
|
+
return new exports.Boom(message, { statusCode: 424, data, ctor: exports.failedDependency });
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
exports.tooEarly = function (message, data) {
|
|
361
|
+
|
|
362
|
+
return new exports.Boom(message, { statusCode: 425, data, ctor: exports.tooEarly });
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
exports.preconditionRequired = function (message, data) {
|
|
367
|
+
|
|
368
|
+
return new exports.Boom(message, { statusCode: 428, data, ctor: exports.preconditionRequired });
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
exports.tooManyRequests = function (message, data) {
|
|
373
|
+
|
|
374
|
+
return new exports.Boom(message, { statusCode: 429, data, ctor: exports.tooManyRequests });
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
exports.illegal = function (message, data) {
|
|
379
|
+
|
|
380
|
+
return new exports.Boom(message, { statusCode: 451, data, ctor: exports.illegal });
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
// 5xx Server Errors
|
|
385
|
+
|
|
386
|
+
exports.internal = function (message, data, statusCode = 500) {
|
|
387
|
+
|
|
388
|
+
return internals.serverError(message, data, statusCode, exports.internal);
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
exports.notImplemented = function (message, data) {
|
|
393
|
+
|
|
394
|
+
return internals.serverError(message, data, 501, exports.notImplemented);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
exports.badGateway = function (message, data) {
|
|
399
|
+
|
|
400
|
+
return internals.serverError(message, data, 502, exports.badGateway);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
exports.serverUnavailable = function (message, data) {
|
|
405
|
+
|
|
406
|
+
return internals.serverError(message, data, 503, exports.serverUnavailable);
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
exports.gatewayTimeout = function (message, data) {
|
|
411
|
+
|
|
412
|
+
return internals.serverError(message, data, 504, exports.gatewayTimeout);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
exports.badImplementation = function (message, data) {
|
|
417
|
+
|
|
418
|
+
const err = internals.serverError(message, data, 500, exports.badImplementation);
|
|
419
|
+
err.isDeveloperError = true;
|
|
420
|
+
return err;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
internals.initialize = function (err, statusCode, message) {
|
|
425
|
+
|
|
426
|
+
const numberCode = parseInt(statusCode, 10);
|
|
427
|
+
Hoek.assert(!isNaN(numberCode) && numberCode >= 400, 'First argument must be a number (400+):', statusCode);
|
|
428
|
+
|
|
429
|
+
err.isBoom = true;
|
|
430
|
+
err.isServer = numberCode >= 500;
|
|
431
|
+
|
|
432
|
+
if (!err.hasOwnProperty('data')) {
|
|
433
|
+
err.data = null;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
err.output = {
|
|
437
|
+
statusCode: numberCode,
|
|
438
|
+
payload: {},
|
|
439
|
+
headers: {}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
Object.defineProperty(err, 'reformat', { value: internals.reformat, configurable: true });
|
|
443
|
+
|
|
444
|
+
if (!message &&
|
|
445
|
+
!err.message) {
|
|
446
|
+
|
|
447
|
+
err.reformat();
|
|
448
|
+
message = err.output.payload.error;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (message) {
|
|
452
|
+
const props = Object.getOwnPropertyDescriptor(err, 'message') || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(err), 'message');
|
|
453
|
+
Hoek.assert(!props || props.configurable && !props.get, 'The error is not compatible with boom');
|
|
454
|
+
|
|
455
|
+
err.message = message + (err.message ? ': ' + err.message : '');
|
|
456
|
+
err.output.payload.message = err.message;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
err.reformat();
|
|
460
|
+
return err;
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
internals.reformat = function (debug = false) {
|
|
465
|
+
|
|
466
|
+
this.output.payload.statusCode = this.output.statusCode;
|
|
467
|
+
this.output.payload.error = internals.codes.get(this.output.statusCode) || 'Unknown';
|
|
468
|
+
|
|
469
|
+
if (this.output.statusCode === 500 && debug !== true) {
|
|
470
|
+
this.output.payload.message = 'An internal server error occurred'; // Hide actual error from user
|
|
471
|
+
}
|
|
472
|
+
else if (this.message) {
|
|
473
|
+
this.output.payload.message = this.message;
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
internals.serverError = function (message, data, statusCode, ctor) {
|
|
479
|
+
|
|
480
|
+
if (data instanceof Error &&
|
|
481
|
+
!data.isBoom) {
|
|
482
|
+
|
|
483
|
+
return exports.boomify(data, { statusCode, message });
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return new exports.Boom(message, { statusCode, data, ctor });
|
|
487
|
+
};
|