@docbrasil/api-systemmanager 1.1.5 → 1.1.7

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 (73) hide show
  1. package/api/user/document.js +65 -1
  2. package/dist/bundle.cjs +73 -11
  3. package/dist/bundle.mjs +1 -1
  4. package/doc/api.md +1286 -509
  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 +1 -1
  17. package/docs/Datasource.html +1 -1
  18. package/docs/Dispatch.html +1 -1
  19. package/docs/Documents.html +470 -9
  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 +1 -1
  57. package/docs/user_datasource.js.html +1 -1
  58. package/docs/user_document.js.html +66 -2
  59. package/docs/user_help.js.html +1 -1
  60. package/docs/user_index.js.html +1 -1
  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
@@ -225,6 +225,71 @@ class Documents {
225
225
  }
226
226
  }
227
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
+
228
293
  /**
229
294
  * @author CloudBrasil <abernardo.br@gmail.com>
230
295
  * @param {object} params Object with params
@@ -722,7 +787,6 @@ class Documents {
722
787
  throw ex;
723
788
  }
724
789
  }
725
-
726
790
  }
727
791
 
728
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
@@ -779,6 +777,71 @@ class Documents {
779
777
  }
780
778
  }
781
779
 
780
+ /**
781
+ * @author CloudBrasil <abernardo.br@gmail.com>
782
+ * @description Updates a document
783
+ * @param {string} id Document _id
784
+ * @param {object} params Object for document payload to update. It has to be the FULL document data, that you can get with findById
785
+ * @param {string} session Session, token JWT
786
+ * @return {Promise}
787
+ * @public
788
+ * @async
789
+ * @example
790
+ *
791
+ * const API = require('@docbrasil/api-systemmanager');
792
+ * const api = new API();
793
+ * const params = { ... };
794
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
795
+ * await api.user.document.findByIdAndUpdate('5edf9f8ee896b817e45b8dad', params, session);
796
+ */
797
+ async findByIdAndUpdate(id, params, session) {
798
+ const self = this;
799
+ try {
800
+ Joi__default["default"].assert(params._id, Joi__default["default"].string().required().error(new Error('_id is required')));
801
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
802
+ Joi__default["default"].assert(session, Joi__default["default"].string().required().error(new Error('session is required')));
803
+ const {areaId, orgId} = params;
804
+ const apiCall = self._client
805
+ .put(`/organizations/${orgId}/areas/${areaId}/documents/${id}`, params, self._setHeader(session));
806
+
807
+ return self._returnData(await apiCall);
808
+ } catch (ex) {
809
+ throw ex;
810
+ }
811
+ }
812
+
813
+ /**
814
+ * @author CloudBrasil <abernardo.br@gmail.com>
815
+ * @description Updates a document.
816
+ * IMPORTANT: if your document has a content, it will NOT bring the content.
817
+ * @param {string} id Document _id
818
+ * @param {string} session Session, token JWT
819
+ * @return {Promise}
820
+ * @public
821
+ * @async
822
+ * @example
823
+ *
824
+ * const API = require('@docbrasil/api-systemmanager');
825
+ * const api = new API();
826
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
827
+ * await api.user.document.findById('5edf9f8ee896b817e45b8dad', session);
828
+ */
829
+ async findById(id, session) {
830
+ const self = this;
831
+ try {
832
+ Joi__default["default"].assert(params._id, Joi__default["default"].string().required().error(new Error('_id is required')));
833
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
834
+ Joi__default["default"].assert(session, Joi__default["default"].string().required().error(new Error('session is required')));
835
+ const {areaId, orgId} = params;
836
+ const apiCall = self._client
837
+ .get(`/organizations/${orgId}/documents/${id}/data/DOC`, params, self._setHeader(session));
838
+
839
+ return self._returnData(await apiCall);
840
+ } catch (ex) {
841
+ throw ex;
842
+ }
843
+ }
844
+
782
845
  /**
783
846
  * @author CloudBrasil <abernardo.br@gmail.com>
784
847
  * @param {object} params Object with params
@@ -1276,7 +1339,6 @@ class Documents {
1276
1339
  throw ex;
1277
1340
  }
1278
1341
  }
1279
-
1280
1342
  }
1281
1343
 
1282
1344
  /**