@docbrasil/api-systemmanager 1.0.78 → 1.0.80

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.
@@ -199,7 +199,6 @@ class Documents {
199
199
  Joi.assert(params.bytes, Joi.number().required().error(new Error('bytes is required')));
200
200
  Joi.assert(params.orgId, Joi.string().required().error(new Error('orgId is required')));
201
201
  Joi.assert(session, Joi.string().required().error(new Error('session is required')));
202
- Joi.assert(params.signedUrl, Joi.string().required().default('').error(new Error('signedUrl is required, even if an empty string')));
203
202
 
204
203
  // Get fields required, and set data default to create document
205
204
  const payloadToSend = self._formatDocument(params);
@@ -386,7 +385,7 @@ class Documents {
386
385
  * const api = new API();
387
386
  * const params - {
388
387
  * documents: [{ _id: '5dadd01dc4af3941d42f8c5c' }],
389
- * orgIdId: '5df7f19618430c89a41a19d2',
388
+ * orgId: '5df7f19618430c89a41a19d2',
390
389
  * };
391
390
  * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
392
391
  * await api.user.document.findByIdsAndRemove(params, session);
@@ -629,6 +628,60 @@ class Documents {
629
628
  return true;
630
629
  }
631
630
 
631
+ /**
632
+ * @author CloudBrasil <abernardo.br@gmail.com>
633
+ * Checks if a document can be added and it does not repeat its primary key
634
+ * @param params
635
+ * @param params.orgId {string} the organization id
636
+ * @param params.docTypeId {string} the id of the doc type
637
+ * @param params.docs {array<object>} an array of documents
638
+ * @param params.docs.id {string} an unique id representing the document
639
+ * @param params.docs.docTypeFields {object} thje docTypeFields of the document
640
+ * @param params.docs.docTypeFieldsData {object} thje docTypeFieldsData of the document
641
+ * @param session
642
+ * @return {Promise<array>} Return the array of the documents that are repeated. If not document is repeaded, then if returns an empty array.
643
+ * @return id {array<string>} the id of the repeated document
644
+ * @public
645
+ * @async
646
+ * @example
647
+ *
648
+ * const API = require('@docbrasil/api-systemmanager');
649
+ * const api = new API();
650
+ * const docTypeFields = [...]; // the doc type fields array
651
+ * const docTypeFieldsData = {...}; // the data of this fields
652
+ * const params - {
653
+ * docs: [{ id: '5dadd01dc4af3941d42f8c5c', docTypeFields, docTypeFieldsData }],
654
+ * orgId: '5df7f19618430c89a41a19d2',
655
+ * docTypeId: '5df7f19618430c89a41a19d5',
656
+ * };
657
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
658
+ * const retDocs = await api.user.document.findByIdsAndRemove(params, session);
659
+ *
660
+ */
661
+ async checkPrimaryKeys(params, session) {
662
+ Joi.assert(params, Joi.object().required().label('params'));
663
+ Joi.assert(params.orgId, Joi.string().required().label('orgId'));
664
+ Joi.assert(params.docTypeId, Joi.string().required().label('docTypeId'));
665
+ Joi.assert(params.docs, Joi.array().required().label('docs'));
666
+ Joi.assert(session, Joi.string().required().label('session'));
667
+
668
+ const { docs = [], orgId = '', docTypeId = '' } = params;
669
+
670
+ if(docs.length === 0) return;
671
+
672
+ try {
673
+ const self = this;
674
+ const payloadToSend = {
675
+ docs,
676
+ docTypeId
677
+ };
678
+ const apiCall = self._client.post(`/organizations/${orgId}/documents/can/add`, payloadToSend, self._setHeader(session));
679
+ return self._returnData(await apiCall);
680
+ } catch (ex) {
681
+ throw ex;
682
+ }
683
+ }
684
+
632
685
  }
633
686
 
634
687
  export default Documents;
package/dist/bundle.cjs CHANGED
@@ -751,7 +751,6 @@ class Documents {
751
751
  Joi__default["default"].assert(params.bytes, Joi__default["default"].number().required().error(new Error('bytes is required')));
752
752
  Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required().error(new Error('orgId is required')));
753
753
  Joi__default["default"].assert(session, Joi__default["default"].string().required().error(new Error('session is required')));
754
- Joi__default["default"].assert(params.signedUrl, Joi__default["default"].string().required().default('').error(new Error('signedUrl is required, even if an empty string')));
755
754
 
756
755
  // Get fields required, and set data default to create document
757
756
  const payloadToSend = self._formatDocument(params);
@@ -938,7 +937,7 @@ class Documents {
938
937
  * const api = new API();
939
938
  * const params - {
940
939
  * documents: [{ _id: '5dadd01dc4af3941d42f8c5c' }],
941
- * orgIdId: '5df7f19618430c89a41a19d2',
940
+ * orgId: '5df7f19618430c89a41a19d2',
942
941
  * };
943
942
  * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
944
943
  * await api.user.document.findByIdsAndRemove(params, session);
@@ -1181,6 +1180,60 @@ class Documents {
1181
1180
  return true;
1182
1181
  }
1183
1182
 
1183
+ /**
1184
+ * @author CloudBrasil <abernardo.br@gmail.com>
1185
+ * Checks if a document can be added and it does not repeat its primary key
1186
+ * @param params
1187
+ * @param params.orgId {string} the organization id
1188
+ * @param params.docTypeId {string} the id of the doc type
1189
+ * @param params.docs {array<object>} an array of documents
1190
+ * @param params.docs.id {string} an unique id representing the document
1191
+ * @param params.docs.docTypeFields {object} thje docTypeFields of the document
1192
+ * @param params.docs.docTypeFieldsData {object} thje docTypeFieldsData of the document
1193
+ * @param session
1194
+ * @return {Promise<array>} Return the array of the documents that are repeated. If not document is repeaded, then if returns an empty array.
1195
+ * @return id {array<string>} the id of the repeated document
1196
+ * @public
1197
+ * @async
1198
+ * @example
1199
+ *
1200
+ * const API = require('@docbrasil/api-systemmanager');
1201
+ * const api = new API();
1202
+ * const docTypeFields = [...]; // the doc type fields array
1203
+ * const docTypeFieldsData = {...}; // the data of this fields
1204
+ * const params - {
1205
+ * docs: [{ id: '5dadd01dc4af3941d42f8c5c', docTypeFields, docTypeFieldsData }],
1206
+ * orgId: '5df7f19618430c89a41a19d2',
1207
+ * docTypeId: '5df7f19618430c89a41a19d5',
1208
+ * };
1209
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
1210
+ * const retDocs = await api.user.document.findByIdsAndRemove(params, session);
1211
+ *
1212
+ */
1213
+ async checkPrimaryKeys(params, session) {
1214
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().label('params'));
1215
+ Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required().label('orgId'));
1216
+ Joi__default["default"].assert(params.docTypeId, Joi__default["default"].string().required().label('docTypeId'));
1217
+ Joi__default["default"].assert(params.docs, Joi__default["default"].array().required().label('docs'));
1218
+ Joi__default["default"].assert(session, Joi__default["default"].string().required().label('session'));
1219
+
1220
+ const { docs = [], orgId = '', docTypeId = '' } = params;
1221
+
1222
+ if(docs.length === 0) return;
1223
+
1224
+ try {
1225
+ const self = this;
1226
+ const payloadToSend = {
1227
+ docs,
1228
+ docTypeId
1229
+ };
1230
+ const apiCall = self._client.post(`/organizations/${orgId}/documents/can/add`, payloadToSend, self._setHeader(session));
1231
+ return self._returnData(await apiCall);
1232
+ } catch (ex) {
1233
+ throw ex;
1234
+ }
1235
+ }
1236
+
1184
1237
  }
1185
1238
 
1186
1239
  /**