@docbrasil/api-systemmanager 1.0.55 → 1.0.56

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/dist/bundle.cjs CHANGED
@@ -1065,7 +1065,7 @@ class Documents {
1065
1065
  * Class for organizations, permission user
1066
1066
  * @class
1067
1067
  */
1068
- class Organization {
1068
+ class Organization$1 {
1069
1069
 
1070
1070
  constructor(options) {
1071
1071
  Joi__default["default"].assert(options, Joi__default["default"].object().required());
@@ -8733,7 +8733,7 @@ class Users {
8733
8733
 
8734
8734
  const self = this;
8735
8735
  self.document = new Documents(options);
8736
- self.organization = new Organization(options);
8736
+ self.organization = new Organization$1(options);
8737
8737
  self.process = new Process(options);
8738
8738
  self.task = new Task(options);
8739
8739
  self.user = self.profile = new User(options);
@@ -10600,6 +10600,125 @@ class AdminDocTypes {
10600
10600
  }
10601
10601
  }
10602
10602
 
10603
+ /**
10604
+ * Class for organizations, permission user
10605
+ * @class
10606
+ */
10607
+ class Organization {
10608
+
10609
+ constructor(options) {
10610
+ Joi__default["default"].assert(options, Joi__default["default"].object().required());
10611
+ Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
10612
+
10613
+ const self = this;
10614
+ self.parent = options.parent;
10615
+ self._client = self.parent.dispatch.getClient();
10616
+ }
10617
+
10618
+ /**
10619
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
10620
+ * @description Get the return data and check for errors
10621
+ * @param {object} retData Response HTTP
10622
+ * @return {*}
10623
+ * @private
10624
+ */
10625
+ _returnData(retData, def = {}) {
10626
+ if (retData.status !== 200) {
10627
+ throw Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
10628
+ } else {
10629
+ return ___default["default"].get(retData, 'data', def);
10630
+ }
10631
+ }
10632
+
10633
+ /**
10634
+ * @author CloudBrasil <abernardo.br@gmail.com>
10635
+ * @description Set header with new session
10636
+ * @param {string} session Session, token JWT
10637
+ * @return {object} header with new session
10638
+ * @private
10639
+ */
10640
+ _setHeader(session) {
10641
+ return {
10642
+ headers: {
10643
+ authorization: session,
10644
+ }
10645
+ };
10646
+ }
10647
+
10648
+ /**
10649
+ * @author CloudBrasil <abernardo.br@gmail.com>
10650
+ * @description Update avatar of organization by session of user not allow session user SU
10651
+ * @param {object} params Params to update avatar
10652
+ * @param {string} params.orgId - Organization id
10653
+ * @param {string} params.avatar - Image in base64 to update
10654
+ * @param {string} params.type - MimeType (image/png)
10655
+ * @param {string} session - Is token JWT of user SU
10656
+ * @return {Promise}
10657
+ * @public
10658
+ * @async
10659
+ * @example
10660
+ *
10661
+ * const API = require('@docbrasil/api-systemmanager');
10662
+ * const api = new API();
10663
+ * const params = {
10664
+ * orgId: '5dadd01dc4af3941d42f8c5c',
10665
+ * avatar: 'iVBORw0KGgoAAAANSUhEUgAAAasAAAHnCAYAAAAGi3J6AAA9BElEQVR...He3/kk/m7kl35S8AAAAASUVORK5CYII=',
10666
+ * type: 'image/png',
10667
+ * };
10668
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
10669
+ * await api.admin.organizations.upsertAvatar(params, session);
10670
+ */
10671
+ async upsertAvatar(params = {}, session) {
10672
+ const self = this;
10673
+
10674
+ try {
10675
+ Joi__default["default"].assert(params, Joi__default["default"].object().required());
10676
+ Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required(), 'Organization id');
10677
+ Joi__default["default"].assert(params.avatar, Joi__default["default"].string().required(), 'Image in base64 to update');
10678
+ Joi__default["default"].assert(params.type, Joi__default["default"].string().required(), 'MimeType (image/png)');
10679
+ Joi__default["default"].assert(session, Joi__default["default"].string().required(), 'Is token JWT of user SU');
10680
+
10681
+ const {orgId, avatar, type} = params;
10682
+ const payload = {avatar, type};
10683
+
10684
+ const apiCall = self._client.put(`/admin/organizations/${orgId}/logo`, payload, self._setHeader(session));
10685
+ return self._returnData(await apiCall);
10686
+ } catch (ex) {
10687
+ throw ex;
10688
+ }
10689
+ }
10690
+
10691
+ /**
10692
+ * @author CloudBrasil <abernardo.br@gmail.com>
10693
+ * @description Remove avatar of user by session of user not allow session user SU
10694
+ * @param {string} params.orgId - Organization id
10695
+ * @param {string} session - Is token JWT of user SU
10696
+ * @return {Promise}
10697
+ * @public
10698
+ * @async
10699
+ * @example
10700
+ *
10701
+ * const API = require('@docbrasil/api-systemmanager');
10702
+ * const api = new API();
10703
+ * const orgId = '5dadd01dc4af3941d42f8c5c';
10704
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
10705
+ * await api.admin.organizations.removeAvatar(orgId, session);
10706
+ */
10707
+ async removeAvatar(orgId, session) {
10708
+ const self = this;
10709
+
10710
+ try {
10711
+ Joi__default["default"].assert(orgId, Joi__default["default"].string().required(), 'Organization id');
10712
+ Joi__default["default"].assert(session, Joi__default["default"].string().required(), 'Is token JWT of user SU');
10713
+
10714
+ const apiCall = self._client.delete(`/admin/organizations/${orgId}/logo`, self._setHeader(session));
10715
+ return self._returnData(await apiCall);
10716
+ } catch (ex) {
10717
+ throw ex;
10718
+ }
10719
+ }
10720
+ }
10721
+
10603
10722
  /**
10604
10723
  * @class API request, admin permission level
10605
10724
  */
@@ -10615,17 +10734,18 @@ class Admin {
10615
10734
  Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
10616
10735
 
10617
10736
  const self = this;
10737
+ self.doctypes = new AdminDocTypes(options);
10618
10738
  self.document = new AdminDocuments(options);
10619
10739
  self.form = new AdminForm(options);
10620
- self.notification = new AdminNotification(options);
10621
10740
  self.list = new AdminLists(options);
10741
+ self.message = new AdminMessage(options);
10742
+ self.organizations = new Organization(options);
10743
+ self.notification = new AdminNotification(options);
10622
10744
  self.plugin = new AdminPlugin(options);
10623
10745
  self.policy = new AdminPolicy(options);
10746
+ self.processes = new AdminProcesses(options);
10624
10747
  self.task = new AdminTask(options);
10625
10748
  self.user = new AdminUser(options);
10626
- self.processes = new AdminProcesses(options);
10627
- self.message = new AdminMessage(options);
10628
- self.doctypes = new AdminDocTypes(options);
10629
10749
  }
10630
10750
  }
10631
10751