@docbrasil/api-systemmanager 1.1.4 → 1.1.6

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.
Files changed (74) hide show
  1. package/api/user/document.js +73 -11
  2. package/dist/bundle.cjs +8 -10
  3. package/dist/bundle.mjs +1 -1
  4. package/doc/api.md +1229 -499
  5. package/docs/Admin.html +1 -1
  6. package/docs/AdminDocuments.html +1 -1
  7. package/docs/AdminForm.html +1 -1
  8. package/docs/AdminLists.html +1 -1
  9. package/docs/AdminMessage.html +1 -1
  10. package/docs/AdminNotification.html +1 -1
  11. package/docs/AdminPlugin.html +1 -1
  12. package/docs/AdminPolicy.html +1 -1
  13. package/docs/AdminProcesses.html +1 -1
  14. package/docs/AdminTask.html +1 -1
  15. package/docs/AdminUser.html +1 -1
  16. package/docs/Application.html +3 -3
  17. package/docs/Datasource.html +1 -1
  18. package/docs/Dispatch.html +1 -1
  19. package/docs/Documents.html +10 -10
  20. package/docs/External.html +1 -1
  21. package/docs/GeoLocation.html +1 -1
  22. package/docs/Help.html +1 -1
  23. package/docs/Login.html +1 -1
  24. package/docs/MyTasks.html +603 -0
  25. package/docs/Notification.html +1 -1
  26. package/docs/Organization.html +1 -1
  27. package/docs/Page.html +1 -1
  28. package/docs/Process.html +1 -1
  29. package/docs/Register.html +1 -1
  30. package/docs/Session.html +1 -1
  31. package/docs/Task.html +5 -5
  32. package/docs/TaskAvailable.html +1 -1
  33. package/docs/Updates.html +1 -1
  34. package/docs/User.html +1 -1
  35. package/docs/Users.html +1 -1
  36. package/docs/admin_doctypes.js.html +1 -1
  37. package/docs/admin_document.js.html +1 -1
  38. package/docs/admin_form.js.html +1 -1
  39. package/docs/admin_index.js.html +1 -1
  40. package/docs/admin_list.js.html +1 -1
  41. package/docs/admin_message.js.html +1 -1
  42. package/docs/admin_notification.js.html +1 -1
  43. package/docs/admin_organization.js.html +1 -1
  44. package/docs/admin_plugin.js.html +1 -1
  45. package/docs/admin_policy.js.html +1 -1
  46. package/docs/admin_processes.js.html +1 -1
  47. package/docs/admin_task.js.html +1 -1
  48. package/docs/admin_user.js.html +1 -1
  49. package/docs/dispatch.js.html +1 -1
  50. package/docs/external.js.html +1 -1
  51. package/docs/general_geoLocation.js.html +1 -1
  52. package/docs/general_index.js.html +1 -1
  53. package/docs/index.html +1 -1
  54. package/docs/login.js.html +1 -1
  55. package/docs/session.js.html +1 -1
  56. package/docs/user_application.js.html +3 -1
  57. package/docs/user_datasource.js.html +1 -1
  58. package/docs/user_document.js.html +9 -11
  59. package/docs/user_help.js.html +1 -1
  60. package/docs/user_index.js.html +2 -2
  61. package/docs/user_my_tasks.js.html +212 -0
  62. package/docs/user_notification.js.html +1 -1
  63. package/docs/user_organization.js.html +1 -1
  64. package/docs/user_page.js.html +1 -1
  65. package/docs/user_process.js.html +1 -1
  66. package/docs/user_register.js.html +1 -1
  67. package/docs/user_task.js.html +3 -1
  68. package/docs/user_task_available.js.html +1 -1
  69. package/docs/user_updates.js.html +1 -1
  70. package/docs/user_user.js.html +1 -1
  71. package/docs/utils_promises.js.html +1 -1
  72. package/package.json +1 -1
  73. package/tests/documents_002.spec.js +107 -0
  74. package/.vscode/settings.json +0 -1
@@ -79,12 +79,15 @@ class Documents {
79
79
  */
80
80
  _formatDocument(params) {
81
81
  try {
82
+ const document = _.get(params, 'document');
83
+ const urlType = _.isEmpty(document) ? '' : _.get(params, 'urlType', 'S3');
84
+ const addType = _.isEmpty(document) ? '' : _.get(params, 'addType', 'S3_SIGNED');
82
85
  return {
83
86
  orgname: _.get(params, 'orgname'),
84
87
  areaId: _.get(params, 'areaId'),
85
88
  docId: _.get(params, 'docId'),
86
89
  documentDate: _.get(params, 'documentDate', Moment().format()),
87
- document: _.get(params, 'document'),
90
+ document,
88
91
  type: _.get(params, 'type'),
89
92
  name: _.get(params, 'name'),
90
93
  content: _.get(params, 'content', ''),
@@ -101,8 +104,8 @@ class Documents {
101
104
  docTypeFields: _.get(params, 'docTypeFields', []), // {"extraId": userId},
102
105
  docTypeFieldsData: _.get(params, 'docTypeFieldsData', {}), // {"extraId": userId},
103
106
  signedUrl: _.get(params, 'signedUrl', ''),
104
- urlType: _.get(params, 'urlType', 'S3'),
105
- addType: _.get(params, 'addType', 'S3_SIGNED'),
107
+ urlType,
108
+ addType
106
109
  };
107
110
  } catch (ex) {
108
111
  throw ex;
@@ -187,17 +190,12 @@ class Documents {
187
190
  */
188
191
  async add(params, session) {
189
192
  const self = this;
190
-
191
193
  try {
192
194
  Joi.assert(params, Joi.object().required().error(new Error('params is required')));
193
- Joi.assert(params.orgname, Joi.string().required().error(new Error('orgname is required')));
195
+ Joi.assert(params.orgId, Joi.string().required().error(new Error('orgId is required')));
194
196
  Joi.assert(params.areaId, Joi.string().required().error(new Error('areaId is required')));
195
- Joi.assert(params.docId, Joi.string().required().error(new Error('docId is required')));
196
- Joi.assert(params.type, Joi.string().required().error(new Error('type is required')));
197
- Joi.assert(params.name, Joi.string().required().error(new Error('name is required')));
197
+ Joi.assert(params.orgname, Joi.string().required().error(new Error('orgname is required')));
198
198
  Joi.assert(params.docTypeId, Joi.string().required().error(new Error('docTypeId is required')));
199
- Joi.assert(params.bytes, Joi.number().required().error(new Error('bytes is required')));
200
- Joi.assert(params.orgId, Joi.string().required().error(new Error('orgId is required')));
201
199
  Joi.assert(session, Joi.string().required().error(new Error('session is required')));
202
200
 
203
201
  // Get fields required, and set data default to create document
@@ -227,6 +225,71 @@ class Documents {
227
225
  }
228
226
  }
229
227
 
228
+ /**
229
+ * @author CloudBrasil <abernardo.br@gmail.com>
230
+ * @description Updates a document
231
+ * @param {string} id Document _id
232
+ * @param {object} params Object for document payload to update. It has to be the FULL document data, that you can get with findById
233
+ * @param {string} session Session, token JWT
234
+ * @return {Promise}
235
+ * @public
236
+ * @async
237
+ * @example
238
+ *
239
+ * const API = require('@docbrasil/api-systemmanager');
240
+ * const api = new API();
241
+ * const params = { ... };
242
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
243
+ * await api.user.document.findByIdAndUpdate('5edf9f8ee896b817e45b8dad', params, session);
244
+ */
245
+ async findByIdAndUpdate(id, params, session) {
246
+ const self = this;
247
+ try {
248
+ Joi.assert(params._id, Joi.string().required().error(new Error('_id is required')));
249
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
250
+ Joi.assert(session, Joi.string().required().error(new Error('session is required')));
251
+ const {areaId, orgId} = params;
252
+ const apiCall = self._client
253
+ .put(`/organizations/${orgId}/areas/${areaId}/documents/${id}`, params, self._setHeader(session));
254
+
255
+ return self._returnData(await apiCall);
256
+ } catch (ex) {
257
+ throw ex;
258
+ }
259
+ }
260
+
261
+ /**
262
+ * @author CloudBrasil <abernardo.br@gmail.com>
263
+ * @description Updates a document.
264
+ * IMPORTANT: if your document has a content, it will NOT bring the content.
265
+ * @param {string} id Document _id
266
+ * @param {string} session Session, token JWT
267
+ * @return {Promise}
268
+ * @public
269
+ * @async
270
+ * @example
271
+ *
272
+ * const API = require('@docbrasil/api-systemmanager');
273
+ * const api = new API();
274
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
275
+ * await api.user.document.findById('5edf9f8ee896b817e45b8dad', session);
276
+ */
277
+ async findById(id, session) {
278
+ const self = this;
279
+ try {
280
+ Joi.assert(params._id, Joi.string().required().error(new Error('_id is required')));
281
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
282
+ Joi.assert(session, Joi.string().required().error(new Error('session is required')));
283
+ const {areaId, orgId} = params;
284
+ const apiCall = self._client
285
+ .get(`/organizations/${orgId}/documents/${id}/data/DOC`, params, self._setHeader(session));
286
+
287
+ return self._returnData(await apiCall);
288
+ } catch (ex) {
289
+ throw ex;
290
+ }
291
+ }
292
+
230
293
  /**
231
294
  * @author CloudBrasil <abernardo.br@gmail.com>
232
295
  * @param {object} params Object with params
@@ -724,7 +787,6 @@ class Documents {
724
787
  throw ex;
725
788
  }
726
789
  }
727
-
728
790
  }
729
791
 
730
792
  export default Documents;
package/dist/bundle.cjs CHANGED
@@ -631,12 +631,15 @@ class Documents {
631
631
  */
632
632
  _formatDocument(params) {
633
633
  try {
634
+ const document = ___default["default"].get(params, 'document');
635
+ const urlType = ___default["default"].isEmpty(document) ? '' : ___default["default"].get(params, 'urlType', 'S3');
636
+ const addType = ___default["default"].isEmpty(document) ? '' : ___default["default"].get(params, 'addType', 'S3_SIGNED');
634
637
  return {
635
638
  orgname: ___default["default"].get(params, 'orgname'),
636
639
  areaId: ___default["default"].get(params, 'areaId'),
637
640
  docId: ___default["default"].get(params, 'docId'),
638
641
  documentDate: ___default["default"].get(params, 'documentDate', Moment__default["default"]().format()),
639
- document: ___default["default"].get(params, 'document'),
642
+ document,
640
643
  type: ___default["default"].get(params, 'type'),
641
644
  name: ___default["default"].get(params, 'name'),
642
645
  content: ___default["default"].get(params, 'content', ''),
@@ -653,8 +656,8 @@ class Documents {
653
656
  docTypeFields: ___default["default"].get(params, 'docTypeFields', []), // {"extraId": userId},
654
657
  docTypeFieldsData: ___default["default"].get(params, 'docTypeFieldsData', {}), // {"extraId": userId},
655
658
  signedUrl: ___default["default"].get(params, 'signedUrl', ''),
656
- urlType: ___default["default"].get(params, 'urlType', 'S3'),
657
- addType: ___default["default"].get(params, 'addType', 'S3_SIGNED'),
659
+ urlType,
660
+ addType
658
661
  };
659
662
  } catch (ex) {
660
663
  throw ex;
@@ -739,17 +742,12 @@ class Documents {
739
742
  */
740
743
  async add(params, session) {
741
744
  const self = this;
742
-
743
745
  try {
744
746
  Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
745
- Joi__default["default"].assert(params.orgname, Joi__default["default"].string().required().error(new Error('orgname is required')));
747
+ Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required().error(new Error('orgId is required')));
746
748
  Joi__default["default"].assert(params.areaId, Joi__default["default"].string().required().error(new Error('areaId is required')));
747
- Joi__default["default"].assert(params.docId, Joi__default["default"].string().required().error(new Error('docId is required')));
748
- Joi__default["default"].assert(params.type, Joi__default["default"].string().required().error(new Error('type is required')));
749
- Joi__default["default"].assert(params.name, Joi__default["default"].string().required().error(new Error('name is required')));
749
+ Joi__default["default"].assert(params.orgname, Joi__default["default"].string().required().error(new Error('orgname is required')));
750
750
  Joi__default["default"].assert(params.docTypeId, Joi__default["default"].string().required().error(new Error('docTypeId is required')));
751
- Joi__default["default"].assert(params.bytes, Joi__default["default"].number().required().error(new Error('bytes is required')));
752
- Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required().error(new Error('orgId is required')));
753
751
  Joi__default["default"].assert(session, Joi__default["default"].string().required().error(new Error('session is required')));
754
752
 
755
753
  // Get fields required, and set data default to create document