@docbrasil/api-systemmanager 1.1.88 → 1.1.90

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.
@@ -355,119 +355,78 @@ class Process {
355
355
  }
356
356
  }
357
357
 
358
- /**
359
- * @author Myndware <augusto.pissarra@myndware.com>
360
- * @description Method to export status data
361
- * @param {object} params Params to export status data
362
- * @param {object} params.query Search process query
363
- * @param {object} params.orgId Organization id (_id database)
364
- * @param {string} session Session, token JWT
365
- * @public
366
- * @example
367
- *
368
- * const API = require('@docbrasil/api-systemmanager');
369
- * const api = new API();
370
- * const params = {
371
- * query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
372
- * orgId: '55e4a3bd6be6b45210833fae',
373
- * };
374
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
375
- * const retSearch = await api.user.process.exportStatusData(params, session);
376
- */
377
- async exportStatusData(params, session) {
378
- const self = this;
379
-
380
- try {
381
- Joi.assert(params, Joi.object().required(), 'Params to export status data');
382
- Joi.assert(params.query, Joi.object().required(), 'The query for the search');
383
- Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
384
- Joi.assert(session, Joi.string().required(), 'Session token JWT');
385
-
386
- const {query, orgId} = params;
387
- const queryString = JSON.stringify(query);
388
- const apiCall = self._client
389
- .get(`/organizations/${orgId}/process/export/status/data?query=${queryString}`, self._setHeader(session));
390
-
391
- return self._returnData(await apiCall);
392
- } catch (ex) {
393
- throw ex;
394
- }
395
- }
358
+ /**
359
+ * @author Myndware <augusto.pissarra@myndware.com>
360
+ * @description Method to export status data
361
+ * @param {object} params Params to export status data
362
+ * @param {object} params.query Search process query
363
+ * @param {object} params.orgId Organization id (_id database)
364
+ * @param {string} session Session, token JWT
365
+ * @public
366
+ * @example
367
+ *
368
+ * const API = require('@docbrasil/api-systemmanager');
369
+ * const api = new API();
370
+ * const params = {
371
+ * query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
372
+ * orgId: '55e4a3bd6be6b45210833fae',
373
+ * };
374
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
375
+ * const retSearch = await api.user.process.exportStatusData(params, session);
376
+ */
377
+ async exportStatusData(params, session) {
378
+ const self = this;
396
379
 
397
- /**
398
- * @author Myndware <augusto.pissarra@myndware.com>
399
- * @description Method to export process data
400
- * @param {object} params Params to export process data
401
- * @param {object} params.query Search process query
402
- * @param {object} params.orgId Organization id (_id database)
403
- * @param {string} session Session, token JWT
404
- * @public
405
- * @example
406
- *
407
- * const API = require('@docbrasil/api-systemmanager');
408
- * const api = new API();
409
- * const params = {
410
- * query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
411
- * orgId: '55e4a3bd6be6b45210833fae',
412
- * };
413
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
414
- * const retSearch = await api.user.process.exportProcessData(params, session);
415
- */
416
- async exportProcessData(params, session) {
417
- const self = this;
418
-
419
- try {
420
- Joi.assert(params, Joi.object().required(), 'Params to export process data');
421
- Joi.assert(params.query, Joi.object().required(), 'The query for the search');
422
- Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
423
- Joi.assert(session, Joi.string().required(), 'Session token JWT');
424
-
425
- const {query, orgId} = params;
426
- const queryString = JSON.stringify(query);
427
- const apiCall = self._client
428
- .get(`/organizations/${orgId}/process/export/collect/data?query=${queryString}`, self._setHeader(session));
429
-
430
- return self._returnData(await apiCall);
431
- } catch (ex) {
432
- throw ex;
433
- }
380
+ try {
381
+ Joi.assert(params, Joi.object().required(), 'Params to export status data');
382
+ Joi.assert(params.query, Joi.object().required(), 'The query for the search');
383
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
384
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
385
+
386
+ const {query, orgId} = params;
387
+ const queryString = JSON.stringify(query);
388
+ const apiCall = self._client
389
+ .get(`/organizations/${orgId}/process/export/status/data?query=${queryString}`, self._setHeader(session));
390
+
391
+ return self._returnData(await apiCall);
392
+ } catch (ex) {
393
+ throw ex;
434
394
  }
395
+ }
435
396
 
436
- /**
437
- * @author Myndware <augusto.pissarra@myndware.com>
438
- * @description Method to get Process Docs
439
- * @param {object} params Params to get process docs
440
- * @param {string} params.orgProcessId Organization Process Id
441
- * @param {string} params.processId Process Id
442
- * @param {string} params.orgId Organization id (_id database)
443
- * @param {string} session Session, token JWT
444
- * @returns {promise} returned data from the get process docs
445
- * @returns {array<object>} Docs returned from process
446
- * @public
447
- * @example
448
- *
449
- * const API = require('@docbrasil/api-systemmanager');
450
- * const api = new API();
451
- * const params = {
452
- * orgProcessId: '55e4a3bd6be6b45210833fae',
453
- * processId: '55e4a3bd6be6b45210833fae',
454
- * orgId: '55e4a3bd6be6b45210833fae',
455
- * };
456
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
457
- * const retSearch = await api.user.process.processDocs(params, session);
458
- */
459
- async processDocs(params, session) {
397
+ /**
398
+ * @author Myndware <augusto.pissarra@myndware.com>
399
+ * @description Method to export process data
400
+ * @param {object} params Params to export process data
401
+ * @param {object} params.query Search process query
402
+ * @param {object} params.orgId Organization id (_id database)
403
+ * @param {string} session Session, token JWT
404
+ * @public
405
+ * @example
406
+ *
407
+ * const API = require('@docbrasil/api-systemmanager');
408
+ * const api = new API();
409
+ * const params = {
410
+ * query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
411
+ * orgId: '55e4a3bd6be6b45210833fae',
412
+ * };
413
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
414
+ * const retSearch = await api.user.process.exportProcessData(params, session);
415
+ */
416
+ async exportProcessData(params, session) {
460
417
  const self = this;
461
418
 
462
419
  try {
463
- Joi.assert(params, Joi.object().required(), 'Params to get process docs');
464
- Joi.assert(params.orgProcessId, Joi.string().required(), 'Organization Process Id');
465
- Joi.assert(params.processId, Joi.string().required(), 'Process Id');
420
+ Joi.assert(params, Joi.object().required(), 'Params to export process data');
421
+ Joi.assert(params.query, Joi.object().required(), 'The query for the search');
466
422
  Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
467
423
  Joi.assert(session, Joi.string().required(), 'Session token JWT');
468
424
 
469
- const {orgProcessId, processId, orgId} = params;
470
- const apiCall = self._client.get(`/organizations/${orgId}/orgprocess/${orgProcessId}/process/${processId}/documents`, self._setHeader(session));
425
+ const {query, orgId} = params;
426
+ const queryString = JSON.stringify(query);
427
+ const apiCall = self._client
428
+ .get(`/organizations/${orgId}/process/export/collect/data?query=${queryString}`, self._setHeader(session));
429
+
471
430
  return self._returnData(await apiCall);
472
431
  } catch (ex) {
473
432
  throw ex;
@@ -475,65 +434,246 @@ class Process {
475
434
  }
476
435
 
477
436
  /**
478
- * @author Myndware <augusto.pissarra@myndware.com>
479
- * @description Method to download the process documents
480
- * @param {object} params Params to download the process documents
481
- * @param {string} params.orgId Organization id (_id database)
482
- * @param {string} params.type Document Type
483
- * @param {array} params.docIds Documents Ids
484
- * @param {string} params.footer Documents Footer
485
- * @param {string} session Session, token JWT
486
- * @returns {promise} returned data from the search
487
- * @public
488
- * @example
489
- *
490
- * const API = require('@docbrasil/api-systemmanager');
491
- * const api = new API();
492
- * const params = {
493
- * orgId: '55e4a3bd6be6b45210833fae',
494
- * type: 'Docs',
495
- * docIds: ['55e4a3bd6be6b45210833fae'],
496
- * footer: 'Documento - {page} de {pages}'
497
- * };
498
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
499
- * const result = await api.user.process.downloadDocs(params, session);
500
- */
437
+ * @author Myndware <augusto.pissarra@myndware.com>
438
+ * @description Method to get Process Docs
439
+ * @param {object} params Params to get process docs
440
+ * @param {string} params.orgProcessId Organization Process Id
441
+ * @param {string} params.processId Process Id
442
+ * @param {string} params.orgId Organization id (_id database)
443
+ * @param {string} session Session, token JWT
444
+ * @returns {promise} returned data from the get process docs
445
+ * @returns {array<object>} Docs returned from process
446
+ * @public
447
+ * @example
448
+ *
449
+ * const API = require('@docbrasil/api-systemmanager');
450
+ * const api = new API();
451
+ * const params = {
452
+ * orgProcessId: '55e4a3bd6be6b45210833fae',
453
+ * processId: '55e4a3bd6be6b45210833fae',
454
+ * orgId: '55e4a3bd6be6b45210833fae',
455
+ * };
456
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
457
+ * const retSearch = await api.user.process.processDocs(params, session);
458
+ */
459
+ async processDocs(params, session) {
460
+ const self = this;
461
+
462
+ try {
463
+ Joi.assert(params, Joi.object().required(), 'Params to get process docs');
464
+ Joi.assert(params.orgProcessId, Joi.string().required(), 'Organization Process Id');
465
+ Joi.assert(params.processId, Joi.string().required(), 'Process Id');
466
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
467
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
468
+
469
+ const {orgProcessId, processId, orgId} = params;
470
+ const apiCall = self._client.get(`/organizations/${orgId}/orgprocess/${orgProcessId}/process/${processId}/documents`, self._setHeader(session));
471
+ return self._returnData(await apiCall);
472
+ } catch (ex) {
473
+ throw ex;
474
+ }
475
+ }
476
+
477
+ /**
478
+ * @author Myndware <augusto.pissarra@myndware.com>
479
+ * @description Method to download the process documents
480
+ * @param {object} params Params to download the process documents
481
+ * @param {string} params.orgId Organization id (_id database)
482
+ * @param {string} params.type Document Type
483
+ * @param {array} params.docIds Documents Ids
484
+ * @param {string} params.footer Documents Footer
485
+ * @param {string} session Session, token JWT
486
+ * @returns {promise} returned data from the search
487
+ * @public
488
+ * @example
489
+ *
490
+ * const API = require('@docbrasil/api-systemmanager');
491
+ * const api = new API();
492
+ * const params = {
493
+ * orgId: '55e4a3bd6be6b45210833fae',
494
+ * type: 'Docs',
495
+ * docIds: ['55e4a3bd6be6b45210833fae'],
496
+ * footer: 'Documento - {page} de {pages}'
497
+ * };
498
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
499
+ * const result = await api.user.process.downloadDocs(params, session);
500
+ */
501
501
  async downloadDocs(params, session) {
502
+ const self = this;
503
+
504
+ try {
505
+ Joi.assert(params, Joi.object().required(), 'Params to download the process documents');
506
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
507
+ Joi.assert(params.type, Joi.string().required(), 'Document Type');
508
+ Joi.assert(params.docIds, Joi.array().required(), 'Document Ids');
509
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
510
+
511
+ const {orgId, type, docIds, footer} = params;
512
+ const data = {
513
+ docIds
514
+ };
515
+
516
+ if (footer) {
517
+ data.footer = footer
518
+ }
519
+
520
+ const apiCall = self._client
521
+ .post(`/organizations/${orgId}/documents/download/${type}`, data, self._setHeader(session));
522
+
523
+ return self._returnData(await apiCall);
524
+ } catch (ex) {
525
+ throw ex;
526
+ }
527
+ }
528
+
529
+ /**
530
+ * @author Myndware <augusto.pissarra@myndware.com>
531
+ * @description Get DocType properties of process
532
+ * @param {object} params Params to get document DocType
533
+ * @param {string} params.docTypeId Document DocTypeId id (_id database);
534
+ * @param {string} params.orgId Organization id (_id database);
535
+ * @param {string} session Session, token JWT
536
+ * @return {Promise}
537
+ * @public
538
+ * @async
539
+ * @example
540
+ *
541
+ * const API = require('@docbrasil/api-systemmanager');
542
+ * const api = new API();
543
+ * const params = {
544
+ * docTypeId: '5dadd01dc4af3941d42f8c5c',
545
+ * orgId: '5edd11c46b6ce9729c2c297c',
546
+ * }
547
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
548
+ * await api.user.process.getOrgDocTypes(params, session);
549
+ */
550
+ async getOrgDocTypes(params, session) {
502
551
  const self = this;
503
552
 
504
553
  try {
505
- Joi.assert(params, Joi.object().required(), 'Params to download the process documents');
506
- Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
507
- Joi.assert(params.type, Joi.string().required(), 'Document Type');
508
- Joi.assert(params.docIds, Joi.array().required(), 'Document Ids');
509
- Joi.assert(session, Joi.string().required(), 'Session token JWT');
554
+ Joi.assert(params, Joi.object().required());
555
+ Joi.assert(params.docTypeId, Joi.string().required());
556
+ Joi.assert(params.orgId, Joi.string().required());
557
+ Joi.assert(session, Joi.string().required());
558
+
559
+ const {docTypeId, orgId} = params;
560
+ const apiCall = self._client.get(`/organizations/${orgId}/doctype/${docTypeId}`, self._setHeader(session));
561
+ return self._returnData(await apiCall);
562
+ } catch (ex) {
563
+ throw ex;
564
+ }
565
+ }
510
566
 
511
- const {orgId, type, docIds, footer} = params;
512
- const data = {
513
- docIds
514
- };
567
+ /**
568
+ * @author Myndware <augusto.pissarra@myndware.com>
569
+ * @description Get Org Groups
570
+ * @param {object} params Params to get Org Groups
571
+ * @param {string} params.orgId Organization id (_id database);
572
+ * @param {string} session Session, token JWT
573
+ * @return {Promise}
574
+ * @public
575
+ * @async
576
+ * @example
577
+ *
578
+ * const API = require('@docbrasil/api-systemmanager');
579
+ * const api = new API();
580
+ * const params = {
581
+ * orgId: '5edd11c46b6ce9729c2c297c',
582
+ * }
583
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
584
+ * await api.user.process.getOrgGroups(params, session);
585
+ */
586
+ async getOrgGroups(params, session) {
587
+ const self = this;
515
588
 
516
- if (footer) {
517
- data.footer = footer
518
- }
589
+ try {
590
+ Joi.assert(params, Joi.object().required());
591
+ Joi.assert(params.orgId, Joi.string().required());
592
+ Joi.assert(session, Joi.string().required());
519
593
 
520
- const apiCall = self._client
521
- .post(`/organizations/${orgId}/documents/download/${type}`, data, self._setHeader(session));
594
+ const {orgId} = params;
595
+ const apiCall = self._client.get(`/organizations/${orgId}/groups`, self._setHeader(session));
596
+ return self._returnData(await apiCall);
597
+ } catch (ex) {
598
+ throw ex;
599
+ }
600
+ }
601
+
602
+ /**
603
+ * @author Myndware <augusto.pissarra@myndware.com>
604
+ * @description Get Org Users
605
+ * @param {object} params Params to get Org Users
606
+ * @param {string} params.orgId Organization id (_id database);
607
+ * @param {array} params.userIds UserIds
608
+ * @param {string} session Session, token JWT
609
+ * @return {Promise}
610
+ * @public
611
+ * @async
612
+ * @example
613
+ *
614
+ * const API = require('@docbrasil/api-systemmanager');
615
+ * const api = new API();
616
+ * const params = {
617
+ * orgId: '5edd11c46b6ce9729c2c297c',
618
+ * userIds: []
619
+ * }
620
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
621
+ * await api.user.process.getOrgUsers(params, session);
622
+ */
623
+ async getOrgUsers(params, session) {
624
+ const self = this;
522
625
 
626
+ try {
627
+ Joi.assert(params, Joi.object().required());
628
+ Joi.assert(params.orgId, Joi.string().required());
629
+ Joi.assert(params.userIds, Joi.array().required());
630
+ Joi.assert(session, Joi.string().required());
631
+
632
+ const {orgId, userIds} = params;
633
+ let queryString = '';
634
+ if(!_.isEmpty(userIds)) {
635
+ queryString = `?userIds=${JSON.stringify(userIds)}&{"sort":{"name":1}}`;
636
+ }
637
+ const apiCall = self._client.get(`/admin/organizations/${orgId}/orgusers${queryString}`, self._setHeader(session));
523
638
  return self._returnData(await apiCall);
524
639
  } catch (ex) {
525
640
  throw ex;
526
641
  }
527
642
  }
528
643
 
644
+ /**
645
+ * @author Myndware <augusto.pissarra@myndware.com>
646
+ * @description Get step history of a process flow
647
+ * @param {object} params Params to get step history
648
+ * @param {string} params.orgId Organization id (_id database);
649
+ * @param {string} params.processId Process id (_id database);
650
+ * @param {string} params.flowId Flow id;
651
+ * @param {string} session Session, token JWT
652
+ * @return {Promise<Array>} Array of step history entries
653
+ * @public
654
+ * @async
655
+ * @example
656
+ *
657
+ * const API = require('@docbrasil/api-systemmanager');
658
+ * const api = new API();
659
+ * const params = {
660
+ * orgId: '5edd11c46b6ce9729c2c297c',
661
+ * processId: '5dadd01dc4af3941d42f8c5c',
662
+ * flowId: 'Task_18v1xx7'
663
+ * }
664
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
665
+ * const stepHistory = await api.user.process.getStepHistory(params, session);
666
+ */
529
667
  /**
530
668
  * @author Myndware <augusto.pissarra@myndware.com>
531
- * @description Get DocType properties of process
532
- * @param {object} params Params to get document DocType
533
- * @param {string} params.docTypeId Document DocTypeId id (_id database);
669
+ * @description Restart a finished process from a specific flow step. Resets the process completion state
670
+ * and triggers re-execution from the specified flow name.
671
+ * @param {object} params Params to restart the process
672
+ * @param {string} params.processId Process id (_id database);
534
673
  * @param {string} params.orgId Organization id (_id database);
674
+ * @param {string} params.flowName The flow name of the step to restart from;
535
675
  * @param {string} session Session, token JWT
536
- * @return {Promise}
676
+ * @return {Promise<object>} { response: 'OK' } on success
537
677
  * @public
538
678
  * @async
539
679
  * @example
@@ -541,36 +681,41 @@ class Process {
541
681
  * const API = require('@docbrasil/api-systemmanager');
542
682
  * const api = new API();
543
683
  * const params = {
544
- * docTypeId: '5dadd01dc4af3941d42f8c5c',
684
+ * processId: '5dadd01dc4af3941d42f8c5c',
545
685
  * orgId: '5edd11c46b6ce9729c2c297c',
546
- * }
686
+ * flowName: 'Task_1'
687
+ * };
547
688
  * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
548
- * await api.user.process.getOrgDocTypes(params, session);
689
+ * await api.user.process.restart(params, session);
549
690
  */
550
- async getOrgDocTypes(params, session) {
551
- const self = this;
552
-
553
- try {
554
- Joi.assert(params, Joi.object().required());
555
- Joi.assert(params.docTypeId, Joi.string().required());
556
- Joi.assert(params.orgId, Joi.string().required());
557
- Joi.assert(session, Joi.string().required());
558
-
559
- const {docTypeId, orgId} = params;
560
- const apiCall = self._client.get(`/organizations/${orgId}/doctype/${docTypeId}`, self._setHeader(session));
561
- return self._returnData(await apiCall);
562
- } catch (ex) {
563
- throw ex;
564
- }
691
+ async restart(params, session) {
692
+ const self = this;
693
+
694
+ try {
695
+ Joi.assert(params, Joi.object().required(), 'Params to restart the process');
696
+ Joi.assert(params.processId, Joi.string().required(), 'Process id (_id database)');
697
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
698
+ Joi.assert(params.flowName, Joi.string().required(), 'Flow name of the step');
699
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
700
+
701
+ const {processId, orgId, flowName} = params;
702
+ const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}/restart/${flowName}`, {}, self._setHeader(session));
703
+ return self._returnData(await apiCall);
704
+ } catch (ex) {
705
+ throw ex;
565
706
  }
707
+ }
566
708
 
567
- /**
709
+ /**
568
710
  * @author Myndware <augusto.pissarra@myndware.com>
569
- * @description Get Org Groups
570
- * @param {object} params Params to get Org Groups
711
+ * @description Re-execute a specific flow step in a running process. Unlike restart, this does not
712
+ * reset the process completion state. Task creation is deferred to the BPMN engine via RabbitMQ.
713
+ * @param {object} params Params to re-execute the process step
714
+ * @param {string} params.processId Process id (_id database);
571
715
  * @param {string} params.orgId Organization id (_id database);
716
+ * @param {string} params.flowName The flow name of the step to re-execute;
572
717
  * @param {string} session Session, token JWT
573
- * @return {Promise}
718
+ * @return {Promise<object>} { response: 'OK' } on success
574
719
  * @public
575
720
  * @async
576
721
  * @example
@@ -578,35 +723,42 @@ class Process {
578
723
  * const API = require('@docbrasil/api-systemmanager');
579
724
  * const api = new API();
580
725
  * const params = {
726
+ * processId: '5dadd01dc4af3941d42f8c5c',
581
727
  * orgId: '5edd11c46b6ce9729c2c297c',
582
- * }
728
+ * flowName: 'Task_1'
729
+ * };
583
730
  * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
584
- * await api.user.process.getOrgGroups(params, session);
731
+ * await api.user.process.reexecute(params, session);
585
732
  */
586
- async getOrgGroups(params, session) {
587
- const self = this;
588
-
589
- try {
590
- Joi.assert(params, Joi.object().required());
591
- Joi.assert(params.orgId, Joi.string().required());
592
- Joi.assert(session, Joi.string().required());
593
-
594
- const {orgId} = params;
595
- const apiCall = self._client.get(`/organizations/${orgId}/groups`, self._setHeader(session));
596
- return self._returnData(await apiCall);
597
- } catch (ex) {
598
- throw ex;
599
- }
733
+ async reexecute(params, session) {
734
+ const self = this;
735
+
736
+ try {
737
+ Joi.assert(params, Joi.object().required(), 'Params to re-execute the process step');
738
+ Joi.assert(params.processId, Joi.string().required(), 'Process id (_id database)');
739
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
740
+ Joi.assert(params.flowName, Joi.string().required(), 'Flow name of the step');
741
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
742
+
743
+ const {processId, orgId, flowName} = params;
744
+ const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}/reexecute/${flowName}`, {}, self._setHeader(session));
745
+ return self._returnData(await apiCall);
746
+ } catch (ex) {
747
+ throw ex;
600
748
  }
749
+ }
601
750
 
602
- /**
751
+ /**
603
752
  * @author Myndware <augusto.pissarra@myndware.com>
604
- * @description Get Org Users
605
- * @param {object} params Params to get Org Users
753
+ * @description Re-execute a specific user task step in a running process, creating a new task
754
+ * synchronously with optional userId reassignment. For non-group tasks, the task is reassigned
755
+ * to the current logged-in user. For group tasks, the original assignment is preserved.
756
+ * @param {object} params Params to re-execute the task
757
+ * @param {string} params.processId Process id (_id database);
606
758
  * @param {string} params.orgId Organization id (_id database);
607
- * @param {array} params.userIds UserIds
759
+ * @param {string} params.flowName The flow name of the user task step to re-execute;
608
760
  * @param {string} session Session, token JWT
609
- * @return {Promise}
761
+ * @return {Promise<object>} { response: 'OK', taskId } on success
610
762
  * @public
611
763
  * @async
612
764
  * @example
@@ -614,73 +766,49 @@ class Process {
614
766
  * const API = require('@docbrasil/api-systemmanager');
615
767
  * const api = new API();
616
768
  * const params = {
769
+ * processId: '5dadd01dc4af3941d42f8c5c',
617
770
  * orgId: '5edd11c46b6ce9729c2c297c',
618
- * userIds: []
619
- * }
771
+ * flowName: 'Task_1'
772
+ * };
620
773
  * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
621
- * await api.user.process.getOrgUsers(params, session);
774
+ * const result = await api.user.process.reexecuteTask(params, session);
775
+ * console.log(result.taskId);
622
776
  */
623
- async getOrgUsers(params, session) {
624
- const self = this;
625
-
626
- try {
627
- Joi.assert(params, Joi.object().required());
628
- Joi.assert(params.orgId, Joi.string().required());
629
- Joi.assert(params.userIds, Joi.array().required());
630
- Joi.assert(session, Joi.string().required());
631
-
632
- const {orgId, userIds} = params;
633
- let queryString = '';
634
- if(!_.isEmpty(userIds)) {
635
- queryString = `?userIds=${JSON.stringify(userIds)}&{"sort":{"name":1}}`;
636
- }
637
- const apiCall = self._client.get(`/admin/organizations/${orgId}/orgusers${queryString}`, self._setHeader(session));
638
- return self._returnData(await apiCall);
639
- } catch (ex) {
640
- throw ex;
641
- }
777
+ async reexecuteTask(params, session) {
778
+ const self = this;
779
+
780
+ try {
781
+ Joi.assert(params, Joi.object().required(), 'Params to re-execute the task');
782
+ Joi.assert(params.processId, Joi.string().required(), 'Process id (_id database)');
783
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
784
+ Joi.assert(params.flowName, Joi.string().required(), 'Flow name of the user task step');
785
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
786
+
787
+ const {processId, orgId, flowName} = params;
788
+ const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}/reexecutetask/${flowName}`, {}, self._setHeader(session));
789
+ return self._returnData(await apiCall);
790
+ } catch (ex) {
791
+ throw ex;
642
792
  }
793
+ }
643
794
 
644
- /**
645
- * @author Myndware <augusto.pissarra@myndware.com>
646
- * @description Get step history of a process flow
647
- * @param {object} params Params to get step history
648
- * @param {string} params.orgId Organization id (_id database);
649
- * @param {string} params.processId Process id (_id database);
650
- * @param {string} params.flowId Flow id;
651
- * @param {string} session Session, token JWT
652
- * @return {Promise<Array>} Array of step history entries
653
- * @public
654
- * @async
655
- * @example
656
- *
657
- * const API = require('@docbrasil/api-systemmanager');
658
- * const api = new API();
659
- * const params = {
660
- * orgId: '5edd11c46b6ce9729c2c297c',
661
- * processId: '5dadd01dc4af3941d42f8c5c',
662
- * flowId: 'Task_18v1xx7'
663
- * }
664
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
665
- * const stepHistory = await api.user.process.getStepHistory(params, session);
666
- */
667
- async getStepHistory(params, session) {
668
- const self = this;
669
-
670
- try {
671
- Joi.assert(params, Joi.object().required());
672
- Joi.assert(params.orgId, Joi.string().required());
673
- Joi.assert(params.processId, Joi.string().required());
674
- Joi.assert(params.flowId, Joi.string().required());
675
- Joi.assert(session, Joi.string().required());
676
-
677
- const {orgId, processId, flowId} = params;
678
- const apiCall = self._client.get(`/organizations/${orgId}/process/${processId}/flow/${flowId}/history`, self._setHeader(session));
679
- return self._returnData(await apiCall, []);
680
- } catch (ex) {
681
- throw ex;
682
- }
795
+ async getStepHistory(params, session) {
796
+ const self = this;
797
+
798
+ try {
799
+ Joi.assert(params, Joi.object().required());
800
+ Joi.assert(params.orgId, Joi.string().required());
801
+ Joi.assert(params.processId, Joi.string().required());
802
+ Joi.assert(params.flowId, Joi.string().required());
803
+ Joi.assert(session, Joi.string().required());
804
+
805
+ const {orgId, processId, flowId} = params;
806
+ const apiCall = self._client.get(`/organizations/${orgId}/process/${processId}/flow/${flowId}/history`, self._setHeader(session));
807
+ return self._returnData(await apiCall, []);
808
+ } catch (ex) {
809
+ throw ex;
683
810
  }
811
+ }
684
812
  }
685
813
 
686
814
  export default Process;