@docbrasil/api-systemmanager 1.1.69 → 1.1.71
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/dashboard.js +93 -7
- package/api/user/document.js +75 -0
- package/dist/bundle.cjs +168 -7
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +60 -0
- package/docs/Documents.html +1057 -16
- package/docs/user_document.js.html +75 -0
- package/package.json +1 -1
package/api/user/dashboard.js
CHANGED
|
@@ -123,6 +123,88 @@ class Chart {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Class user access to reports
|
|
128
|
+
* @class
|
|
129
|
+
*/
|
|
130
|
+
class Report {
|
|
131
|
+
constructor(options) {
|
|
132
|
+
Joi.assert(options, Joi.object().required());
|
|
133
|
+
Joi.assert(options.parent, Joi.object().required());
|
|
134
|
+
|
|
135
|
+
const self = this;
|
|
136
|
+
self.parent = options.parent;
|
|
137
|
+
self._client = self.parent.dispatch.getClient();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
142
|
+
* @description Get the return data and check for errors
|
|
143
|
+
* @param {object} retData Response HTTP
|
|
144
|
+
* @return {*}
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
_returnData(retData, def = {}) {
|
|
148
|
+
if (retData.status !== 200) {
|
|
149
|
+
return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
|
|
150
|
+
} else {
|
|
151
|
+
return _.get(retData, 'data', def);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @author Myndware <augusto.pissarra@myndware.com>
|
|
157
|
+
* @description Set header with new session
|
|
158
|
+
* @param {string} session Session, token JWT
|
|
159
|
+
* @return {object} header with new session
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
_setHeader(session) {
|
|
163
|
+
return {
|
|
164
|
+
headers: {
|
|
165
|
+
Authorization: session,
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @author Myndware <augusto.pissarra@myndware.com>
|
|
172
|
+
* @description Get the data for a report
|
|
173
|
+
* @param {object} params Params to get helps from topic
|
|
174
|
+
* @param {object} params.type Type of the report data
|
|
175
|
+
* @param {object} params.query The query if any (to search documents)
|
|
176
|
+
* @param {string} session Session, token JWT
|
|
177
|
+
* @returns {promise}
|
|
178
|
+
* @public
|
|
179
|
+
* @example
|
|
180
|
+
*
|
|
181
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
182
|
+
* const api = new API();
|
|
183
|
+
* const params = {
|
|
184
|
+
* type: '[REPORTS] Myndie:vat_data',
|
|
185
|
+
* query: { ... } // the last query to search documents
|
|
186
|
+
* };
|
|
187
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
188
|
+
* await api.user.dashboard.report.getData(params, session);
|
|
189
|
+
*/
|
|
190
|
+
async getData(params, session) {
|
|
191
|
+
const self = this;
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
Joi.assert(params, Joi.object().required(), 'Params to helps from a topic');
|
|
195
|
+
Joi.assert(params.type, Joi.string().required(), 'Type of graph');
|
|
196
|
+
Joi.assert(session, Joi.string().required(), 'Session token JWT');
|
|
197
|
+
|
|
198
|
+
const { type, query = {} } = params;
|
|
199
|
+
const apiCall = self._client.post(`/organizations/dashboard/report/data/${type}`, query, self._setHeader(session));
|
|
200
|
+
|
|
201
|
+
return self._returnData(await apiCall);
|
|
202
|
+
} catch (ex) {
|
|
203
|
+
throw ex;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
126
208
|
/**
|
|
127
209
|
* Class user access to dashboards
|
|
128
210
|
* @class
|
|
@@ -137,6 +219,7 @@ class Dashboard {
|
|
|
137
219
|
self.parent = options.parent;
|
|
138
220
|
self._client = self.parent.dispatch.getClient();
|
|
139
221
|
self._chart = new Chart(options);
|
|
222
|
+
self._report = new Report(options);
|
|
140
223
|
}
|
|
141
224
|
|
|
142
225
|
/**
|
|
@@ -173,18 +256,21 @@ class Dashboard {
|
|
|
173
256
|
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
174
257
|
* @description return the chart
|
|
175
258
|
* @public
|
|
176
|
-
* @async
|
|
177
|
-
* @example
|
|
178
|
-
*
|
|
179
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
180
|
-
* const api = new API();
|
|
181
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
182
|
-
* await api.user.help.getTopics({}, session);
|
|
183
259
|
*/
|
|
184
260
|
get chart() {
|
|
185
261
|
const self = this;
|
|
186
262
|
return self._chart;
|
|
187
263
|
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
267
|
+
* @description return the report
|
|
268
|
+
* @public
|
|
269
|
+
*/
|
|
270
|
+
get report() {
|
|
271
|
+
const self = this;
|
|
272
|
+
return self._report;
|
|
273
|
+
}
|
|
188
274
|
}
|
|
189
275
|
|
|
190
276
|
export default Dashboard;
|
package/api/user/document.js
CHANGED
|
@@ -238,6 +238,81 @@ class Documents {
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
/**
|
|
242
|
+
* @author Myndware <augusto.pissarra@myndware.com>
|
|
243
|
+
* @description Add multiple documents to a doc area under a doc type
|
|
244
|
+
* @param {object} params Object for adding documents
|
|
245
|
+
* @param {string} params.orgId Organization id (_id database)
|
|
246
|
+
* @param {string} params.userId User id (_id database)
|
|
247
|
+
* @param {string} params.docAreaName The name of the doc area
|
|
248
|
+
* @param {string} params.docTypeName The name of the doc type
|
|
249
|
+
* @param {array<object>} params.docs Array of documents to add
|
|
250
|
+
* @param {string} [params.docs.document=''] The url to the document on S3, an external URL or a base64 representation of the document
|
|
251
|
+
* @param {string} [params.docs.type=''] The mime type of the document
|
|
252
|
+
* @param {string} [params.docs.name=''] The name of the document
|
|
253
|
+
* @param {string} [params.docs.content=''] The content of the document
|
|
254
|
+
* @param {number} [params.docs.bytes=0] The bytes (in kb) of the document
|
|
255
|
+
* @param {string} [params.docs.urlType=''] The urlType of the document
|
|
256
|
+
* @param {string} [params.docs.description=''] The description of the document
|
|
257
|
+
* @param {string} [params.docs.category=''] The category of the document
|
|
258
|
+
* @param {array<string>} [params.docs.tags=[]] The tags of the document
|
|
259
|
+
* @param {object} [params.docs.docTypeFieldsData={}] The data related to this document
|
|
260
|
+
* @param {boolean} [params.docs.hasPhisicalStorage=false] The flag to define if the document has physical storage or not
|
|
261
|
+
* @param {string} [params.docs.boxId=''] The boxId if we define the document has physical storage
|
|
262
|
+
* @param {number} [params.docs.status] The document status
|
|
263
|
+
* @param {string} [params.docs.storageStatus=''] The storageStatus if we define the document has physical storage
|
|
264
|
+
* @param {string} session Session, token JWT
|
|
265
|
+
* @return {Promise<object>} The result of the operation
|
|
266
|
+
* @return {boolean} return.success True if the operation was successful
|
|
267
|
+
* @return {array<object>} return.added Array of added documents
|
|
268
|
+
* @return {array<object>} return.notAdded Array of documents that could not be added
|
|
269
|
+
* @public
|
|
270
|
+
* @async
|
|
271
|
+
* @example
|
|
272
|
+
*
|
|
273
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
274
|
+
* const api = new API();
|
|
275
|
+
* const params = {
|
|
276
|
+
* orgId: '5df7f19618430c89a41a19d2',
|
|
277
|
+
* userId: '5df7f19618430c89a41a19d3',
|
|
278
|
+
* docAreaName: 'My Doc Area',
|
|
279
|
+
* docTypeName: 'My Doc Type',
|
|
280
|
+
* docs: [
|
|
281
|
+
* {
|
|
282
|
+
* document: 'https://s3.amazonaws.com/...',
|
|
283
|
+
* type: 'application/pdf',
|
|
284
|
+
* name: 'Document 1',
|
|
285
|
+
* description: 'First document',
|
|
286
|
+
* category: 'Category 1',
|
|
287
|
+
* tags: ['tag1', 'tag2'],
|
|
288
|
+
* docTypeFieldsData: { extraField: 'value' },
|
|
289
|
+
* bytes: 12345
|
|
290
|
+
* }
|
|
291
|
+
* ]
|
|
292
|
+
* };
|
|
293
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
294
|
+
* const result = await api.user.document.addDocuments(params, session);
|
|
295
|
+
*/
|
|
296
|
+
async addDocuments(params, session) {
|
|
297
|
+
const self = this;
|
|
298
|
+
try {
|
|
299
|
+
Joi.assert(params, Joi.object().required().error(new Error('params is required')));
|
|
300
|
+
Joi.assert(params.orgId, Joi.string().required().error(new Error('orgId is required')));
|
|
301
|
+
Joi.assert(params.userId, Joi.string().required().error(new Error('userId is required')));
|
|
302
|
+
Joi.assert(params.docAreaName, Joi.string().required().error(new Error('docAreaName is required')));
|
|
303
|
+
Joi.assert(params.docTypeName, Joi.string().required().error(new Error('docTypeName is required')));
|
|
304
|
+
Joi.assert(params.docs, Joi.array().required().error(new Error('docs is required')));
|
|
305
|
+
Joi.assert(session, Joi.string().required().error(new Error('session is required')));
|
|
306
|
+
|
|
307
|
+
const apiCall = self._client
|
|
308
|
+
.put('/organizations/documents', params, self._setHeader(session));
|
|
309
|
+
|
|
310
|
+
return self._returnData(await apiCall);
|
|
311
|
+
} catch (ex) {
|
|
312
|
+
throw ex;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
241
316
|
/**
|
|
242
317
|
* @author Myndware <augusto.pissarra@myndware.com>
|
|
243
318
|
* @description Updates a document
|
package/dist/bundle.cjs
CHANGED
|
@@ -892,6 +892,81 @@ class Documents {
|
|
|
892
892
|
}
|
|
893
893
|
}
|
|
894
894
|
|
|
895
|
+
/**
|
|
896
|
+
* @author Myndware <augusto.pissarra@myndware.com>
|
|
897
|
+
* @description Add multiple documents to a doc area under a doc type
|
|
898
|
+
* @param {object} params Object for adding documents
|
|
899
|
+
* @param {string} params.orgId Organization id (_id database)
|
|
900
|
+
* @param {string} params.userId User id (_id database)
|
|
901
|
+
* @param {string} params.docAreaName The name of the doc area
|
|
902
|
+
* @param {string} params.docTypeName The name of the doc type
|
|
903
|
+
* @param {array<object>} params.docs Array of documents to add
|
|
904
|
+
* @param {string} [params.docs.document=''] The url to the document on S3, an external URL or a base64 representation of the document
|
|
905
|
+
* @param {string} [params.docs.type=''] The mime type of the document
|
|
906
|
+
* @param {string} [params.docs.name=''] The name of the document
|
|
907
|
+
* @param {string} [params.docs.content=''] The content of the document
|
|
908
|
+
* @param {number} [params.docs.bytes=0] The bytes (in kb) of the document
|
|
909
|
+
* @param {string} [params.docs.urlType=''] The urlType of the document
|
|
910
|
+
* @param {string} [params.docs.description=''] The description of the document
|
|
911
|
+
* @param {string} [params.docs.category=''] The category of the document
|
|
912
|
+
* @param {array<string>} [params.docs.tags=[]] The tags of the document
|
|
913
|
+
* @param {object} [params.docs.docTypeFieldsData={}] The data related to this document
|
|
914
|
+
* @param {boolean} [params.docs.hasPhisicalStorage=false] The flag to define if the document has physical storage or not
|
|
915
|
+
* @param {string} [params.docs.boxId=''] The boxId if we define the document has physical storage
|
|
916
|
+
* @param {number} [params.docs.status] The document status
|
|
917
|
+
* @param {string} [params.docs.storageStatus=''] The storageStatus if we define the document has physical storage
|
|
918
|
+
* @param {string} session Session, token JWT
|
|
919
|
+
* @return {Promise<object>} The result of the operation
|
|
920
|
+
* @return {boolean} return.success True if the operation was successful
|
|
921
|
+
* @return {array<object>} return.added Array of added documents
|
|
922
|
+
* @return {array<object>} return.notAdded Array of documents that could not be added
|
|
923
|
+
* @public
|
|
924
|
+
* @async
|
|
925
|
+
* @example
|
|
926
|
+
*
|
|
927
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
928
|
+
* const api = new API();
|
|
929
|
+
* const params = {
|
|
930
|
+
* orgId: '5df7f19618430c89a41a19d2',
|
|
931
|
+
* userId: '5df7f19618430c89a41a19d3',
|
|
932
|
+
* docAreaName: 'My Doc Area',
|
|
933
|
+
* docTypeName: 'My Doc Type',
|
|
934
|
+
* docs: [
|
|
935
|
+
* {
|
|
936
|
+
* document: 'https://s3.amazonaws.com/...',
|
|
937
|
+
* type: 'application/pdf',
|
|
938
|
+
* name: 'Document 1',
|
|
939
|
+
* description: 'First document',
|
|
940
|
+
* category: 'Category 1',
|
|
941
|
+
* tags: ['tag1', 'tag2'],
|
|
942
|
+
* docTypeFieldsData: { extraField: 'value' },
|
|
943
|
+
* bytes: 12345
|
|
944
|
+
* }
|
|
945
|
+
* ]
|
|
946
|
+
* };
|
|
947
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
948
|
+
* const result = await api.user.document.addDocuments(params, session);
|
|
949
|
+
*/
|
|
950
|
+
async addDocuments(params, session) {
|
|
951
|
+
const self = this;
|
|
952
|
+
try {
|
|
953
|
+
Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
|
|
954
|
+
Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required().error(new Error('orgId is required')));
|
|
955
|
+
Joi__default["default"].assert(params.userId, Joi__default["default"].string().required().error(new Error('userId is required')));
|
|
956
|
+
Joi__default["default"].assert(params.docAreaName, Joi__default["default"].string().required().error(new Error('docAreaName is required')));
|
|
957
|
+
Joi__default["default"].assert(params.docTypeName, Joi__default["default"].string().required().error(new Error('docTypeName is required')));
|
|
958
|
+
Joi__default["default"].assert(params.docs, Joi__default["default"].array().required().error(new Error('docs is required')));
|
|
959
|
+
Joi__default["default"].assert(session, Joi__default["default"].string().required().error(new Error('session is required')));
|
|
960
|
+
|
|
961
|
+
const apiCall = self._client
|
|
962
|
+
.put('/organizations/documents', params, self._setHeader(session));
|
|
963
|
+
|
|
964
|
+
return self._returnData(await apiCall);
|
|
965
|
+
} catch (ex) {
|
|
966
|
+
throw ex;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
895
970
|
/**
|
|
896
971
|
* @author Myndware <augusto.pissarra@myndware.com>
|
|
897
972
|
* @description Updates a document
|
|
@@ -11794,6 +11869,88 @@ class Chart {
|
|
|
11794
11869
|
}
|
|
11795
11870
|
}
|
|
11796
11871
|
|
|
11872
|
+
/**
|
|
11873
|
+
* Class user access to reports
|
|
11874
|
+
* @class
|
|
11875
|
+
*/
|
|
11876
|
+
class Report {
|
|
11877
|
+
constructor(options) {
|
|
11878
|
+
Joi__default["default"].assert(options, Joi__default["default"].object().required());
|
|
11879
|
+
Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
|
|
11880
|
+
|
|
11881
|
+
const self = this;
|
|
11882
|
+
self.parent = options.parent;
|
|
11883
|
+
self._client = self.parent.dispatch.getClient();
|
|
11884
|
+
}
|
|
11885
|
+
|
|
11886
|
+
/**
|
|
11887
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
11888
|
+
* @description Get the return data and check for errors
|
|
11889
|
+
* @param {object} retData Response HTTP
|
|
11890
|
+
* @return {*}
|
|
11891
|
+
* @private
|
|
11892
|
+
*/
|
|
11893
|
+
_returnData(retData, def = {}) {
|
|
11894
|
+
if (retData.status !== 200) {
|
|
11895
|
+
return Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
|
|
11896
|
+
} else {
|
|
11897
|
+
return ___default["default"].get(retData, 'data', def);
|
|
11898
|
+
}
|
|
11899
|
+
}
|
|
11900
|
+
|
|
11901
|
+
/**
|
|
11902
|
+
* @author Myndware <augusto.pissarra@myndware.com>
|
|
11903
|
+
* @description Set header with new session
|
|
11904
|
+
* @param {string} session Session, token JWT
|
|
11905
|
+
* @return {object} header with new session
|
|
11906
|
+
* @private
|
|
11907
|
+
*/
|
|
11908
|
+
_setHeader(session) {
|
|
11909
|
+
return {
|
|
11910
|
+
headers: {
|
|
11911
|
+
Authorization: session,
|
|
11912
|
+
}
|
|
11913
|
+
};
|
|
11914
|
+
}
|
|
11915
|
+
|
|
11916
|
+
/**
|
|
11917
|
+
* @author Myndware <augusto.pissarra@myndware.com>
|
|
11918
|
+
* @description Get the data for a report
|
|
11919
|
+
* @param {object} params Params to get helps from topic
|
|
11920
|
+
* @param {object} params.type Type of the report data
|
|
11921
|
+
* @param {object} params.query The query if any (to search documents)
|
|
11922
|
+
* @param {string} session Session, token JWT
|
|
11923
|
+
* @returns {promise}
|
|
11924
|
+
* @public
|
|
11925
|
+
* @example
|
|
11926
|
+
*
|
|
11927
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
11928
|
+
* const api = new API();
|
|
11929
|
+
* const params = {
|
|
11930
|
+
* type: '[REPORTS] Myndie:vat_data',
|
|
11931
|
+
* query: { ... } // the last query to search documents
|
|
11932
|
+
* };
|
|
11933
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
11934
|
+
* await api.user.dashboard.report.getData(params, session);
|
|
11935
|
+
*/
|
|
11936
|
+
async getData(params, session) {
|
|
11937
|
+
const self = this;
|
|
11938
|
+
|
|
11939
|
+
try {
|
|
11940
|
+
Joi__default["default"].assert(params, Joi__default["default"].object().required(), 'Params to helps from a topic');
|
|
11941
|
+
Joi__default["default"].assert(params.type, Joi__default["default"].string().required(), 'Type of graph');
|
|
11942
|
+
Joi__default["default"].assert(session, Joi__default["default"].string().required(), 'Session token JWT');
|
|
11943
|
+
|
|
11944
|
+
const { type, query = {} } = params;
|
|
11945
|
+
const apiCall = self._client.post(`/organizations/dashboard/report/data/${type}`, query, self._setHeader(session));
|
|
11946
|
+
|
|
11947
|
+
return self._returnData(await apiCall);
|
|
11948
|
+
} catch (ex) {
|
|
11949
|
+
throw ex;
|
|
11950
|
+
}
|
|
11951
|
+
}
|
|
11952
|
+
}
|
|
11953
|
+
|
|
11797
11954
|
/**
|
|
11798
11955
|
* Class user access to dashboards
|
|
11799
11956
|
* @class
|
|
@@ -11808,6 +11965,7 @@ class Dashboard {
|
|
|
11808
11965
|
self.parent = options.parent;
|
|
11809
11966
|
self._client = self.parent.dispatch.getClient();
|
|
11810
11967
|
self._chart = new Chart(options);
|
|
11968
|
+
self._report = new Report(options);
|
|
11811
11969
|
}
|
|
11812
11970
|
|
|
11813
11971
|
/**
|
|
@@ -11844,18 +12002,21 @@ class Dashboard {
|
|
|
11844
12002
|
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
11845
12003
|
* @description return the chart
|
|
11846
12004
|
* @public
|
|
11847
|
-
* @async
|
|
11848
|
-
* @example
|
|
11849
|
-
*
|
|
11850
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
11851
|
-
* const api = new API();
|
|
11852
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
11853
|
-
* await api.user.help.getTopics({}, session);
|
|
11854
12005
|
*/
|
|
11855
12006
|
get chart() {
|
|
11856
12007
|
const self = this;
|
|
11857
12008
|
return self._chart;
|
|
11858
12009
|
}
|
|
12010
|
+
|
|
12011
|
+
/**
|
|
12012
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
12013
|
+
* @description return the report
|
|
12014
|
+
* @public
|
|
12015
|
+
*/
|
|
12016
|
+
get report() {
|
|
12017
|
+
const self = this;
|
|
12018
|
+
return self._report;
|
|
12019
|
+
}
|
|
11859
12020
|
}
|
|
11860
12021
|
|
|
11861
12022
|
/**
|