@docbrasil/api-systemmanager 1.1.6 → 1.1.8
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/document.js +15 -2
- package/dist/bundle.cjs +80 -3
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +47 -0
- package/docs/Documents.html +469 -8
- package/docs/user_document.js.html +65 -1
- package/package.json +1 -1
package/api/user/document.js
CHANGED
|
@@ -3,6 +3,19 @@ import Boom from '@hapi/boom';
|
|
|
3
3
|
import Joi from 'joi';
|
|
4
4
|
import Moment from 'moment';
|
|
5
5
|
|
|
6
|
+
const Random = {
|
|
7
|
+
S4: function () {
|
|
8
|
+
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
9
|
+
},
|
|
10
|
+
guid: function (separator) {
|
|
11
|
+
var separator = (_.isUndefined(separator) ? "" : separator);
|
|
12
|
+
return (this.S4() + this.S4() + separator + this.S4() + separator + this.S4() + separator + this.S4() + separator + this.S4() + this.S4() + this.S4());
|
|
13
|
+
},
|
|
14
|
+
code: function () {
|
|
15
|
+
return this.S4().toUpperCase() + '-' + this.S4().toUpperCase() + '-' + this.S4().toUpperCase();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
6
19
|
/**
|
|
7
20
|
* Class for documents, permission user
|
|
8
21
|
* @class
|
|
@@ -79,13 +92,13 @@ class Documents {
|
|
|
79
92
|
*/
|
|
80
93
|
_formatDocument(params) {
|
|
81
94
|
try {
|
|
82
|
-
const document = _.get(params, 'document');
|
|
95
|
+
const document = _.get(params, 'document', '');
|
|
83
96
|
const urlType = _.isEmpty(document) ? '' : _.get(params, 'urlType', 'S3');
|
|
84
97
|
const addType = _.isEmpty(document) ? '' : _.get(params, 'addType', 'S3_SIGNED');
|
|
85
98
|
return {
|
|
86
99
|
orgname: _.get(params, 'orgname'),
|
|
87
100
|
areaId: _.get(params, 'areaId'),
|
|
88
|
-
docId: _.get(params, 'docId'),
|
|
101
|
+
docId: _.get(params, 'docId', Random.code()),
|
|
89
102
|
documentDate: _.get(params, 'documentDate', Moment().format()),
|
|
90
103
|
document,
|
|
91
104
|
type: _.get(params, 'type'),
|
package/dist/bundle.cjs
CHANGED
|
@@ -555,6 +555,19 @@ class Users$1 {
|
|
|
555
555
|
}
|
|
556
556
|
}
|
|
557
557
|
|
|
558
|
+
const Random = {
|
|
559
|
+
S4: function () {
|
|
560
|
+
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
561
|
+
},
|
|
562
|
+
guid: function (separator) {
|
|
563
|
+
var separator = (___default["default"].isUndefined(separator) ? "" : separator);
|
|
564
|
+
return (this.S4() + this.S4() + separator + this.S4() + separator + this.S4() + separator + this.S4() + separator + this.S4() + this.S4() + this.S4());
|
|
565
|
+
},
|
|
566
|
+
code: function () {
|
|
567
|
+
return this.S4().toUpperCase() + '-' + this.S4().toUpperCase() + '-' + this.S4().toUpperCase();
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
|
|
558
571
|
/**
|
|
559
572
|
* Class for documents, permission user
|
|
560
573
|
* @class
|
|
@@ -631,13 +644,13 @@ class Documents {
|
|
|
631
644
|
*/
|
|
632
645
|
_formatDocument(params) {
|
|
633
646
|
try {
|
|
634
|
-
const document = ___default["default"].get(params, 'document');
|
|
647
|
+
const document = ___default["default"].get(params, 'document', '');
|
|
635
648
|
const urlType = ___default["default"].isEmpty(document) ? '' : ___default["default"].get(params, 'urlType', 'S3');
|
|
636
649
|
const addType = ___default["default"].isEmpty(document) ? '' : ___default["default"].get(params, 'addType', 'S3_SIGNED');
|
|
637
650
|
return {
|
|
638
651
|
orgname: ___default["default"].get(params, 'orgname'),
|
|
639
652
|
areaId: ___default["default"].get(params, 'areaId'),
|
|
640
|
-
docId: ___default["default"].get(params, 'docId'),
|
|
653
|
+
docId: ___default["default"].get(params, 'docId', Random.code()),
|
|
641
654
|
documentDate: ___default["default"].get(params, 'documentDate', Moment__default["default"]().format()),
|
|
642
655
|
document,
|
|
643
656
|
type: ___default["default"].get(params, 'type'),
|
|
@@ -777,6 +790,71 @@ class Documents {
|
|
|
777
790
|
}
|
|
778
791
|
}
|
|
779
792
|
|
|
793
|
+
/**
|
|
794
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
795
|
+
* @description Updates a document
|
|
796
|
+
* @param {string} id Document _id
|
|
797
|
+
* @param {object} params Object for document payload to update. It has to be the FULL document data, that you can get with findById
|
|
798
|
+
* @param {string} session Session, token JWT
|
|
799
|
+
* @return {Promise}
|
|
800
|
+
* @public
|
|
801
|
+
* @async
|
|
802
|
+
* @example
|
|
803
|
+
*
|
|
804
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
805
|
+
* const api = new API();
|
|
806
|
+
* const params = { ... };
|
|
807
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
808
|
+
* await api.user.document.findByIdAndUpdate('5edf9f8ee896b817e45b8dad', params, session);
|
|
809
|
+
*/
|
|
810
|
+
async findByIdAndUpdate(id, params, session) {
|
|
811
|
+
const self = this;
|
|
812
|
+
try {
|
|
813
|
+
Joi__default["default"].assert(params._id, Joi__default["default"].string().required().error(new Error('_id is required')));
|
|
814
|
+
Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
|
|
815
|
+
Joi__default["default"].assert(session, Joi__default["default"].string().required().error(new Error('session is required')));
|
|
816
|
+
const {areaId, orgId} = params;
|
|
817
|
+
const apiCall = self._client
|
|
818
|
+
.put(`/organizations/${orgId}/areas/${areaId}/documents/${id}`, params, self._setHeader(session));
|
|
819
|
+
|
|
820
|
+
return self._returnData(await apiCall);
|
|
821
|
+
} catch (ex) {
|
|
822
|
+
throw ex;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
828
|
+
* @description Updates a document.
|
|
829
|
+
* IMPORTANT: if your document has a content, it will NOT bring the content.
|
|
830
|
+
* @param {string} id Document _id
|
|
831
|
+
* @param {string} session Session, token JWT
|
|
832
|
+
* @return {Promise}
|
|
833
|
+
* @public
|
|
834
|
+
* @async
|
|
835
|
+
* @example
|
|
836
|
+
*
|
|
837
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
838
|
+
* const api = new API();
|
|
839
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
840
|
+
* await api.user.document.findById('5edf9f8ee896b817e45b8dad', session);
|
|
841
|
+
*/
|
|
842
|
+
async findById(id, session) {
|
|
843
|
+
const self = this;
|
|
844
|
+
try {
|
|
845
|
+
Joi__default["default"].assert(params._id, Joi__default["default"].string().required().error(new Error('_id is required')));
|
|
846
|
+
Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
|
|
847
|
+
Joi__default["default"].assert(session, Joi__default["default"].string().required().error(new Error('session is required')));
|
|
848
|
+
const {areaId, orgId} = params;
|
|
849
|
+
const apiCall = self._client
|
|
850
|
+
.get(`/organizations/${orgId}/documents/${id}/data/DOC`, params, self._setHeader(session));
|
|
851
|
+
|
|
852
|
+
return self._returnData(await apiCall);
|
|
853
|
+
} catch (ex) {
|
|
854
|
+
throw ex;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
|
|
780
858
|
/**
|
|
781
859
|
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
782
860
|
* @param {object} params Object with params
|
|
@@ -1274,7 +1352,6 @@ class Documents {
|
|
|
1274
1352
|
throw ex;
|
|
1275
1353
|
}
|
|
1276
1354
|
}
|
|
1277
|
-
|
|
1278
1355
|
}
|
|
1279
1356
|
|
|
1280
1357
|
/**
|