@docbrasil/api-systemmanager 1.1.89 → 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.
@@ -268,119 +268,78 @@ class Process {
268
268
  }
269
269
  }
270
270
 
271
- /**
272
- * @author Myndware <augusto.pissarra@myndware.com>
273
- * @description Method to export status data
274
- * @param {object} params Params to export status data
275
- * @param {object} params.query Search process query
276
- * @param {object} params.orgId Organization id (_id database)
277
- * @param {string} session Session, token JWT
278
- * @public
279
- * @example
280
- *
281
- * const API = require('@docbrasil/api-systemmanager');
282
- * const api = new API();
283
- * const params = {
284
- * query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
285
- * orgId: '55e4a3bd6be6b45210833fae',
286
- * };
287
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
288
- * const retSearch = await api.user.process.exportStatusData(params, session);
289
- */
290
- async exportStatusData(params, session) {
291
- const self = this;
292
-
293
- try {
294
- Joi.assert(params, Joi.object().required(), 'Params to export status data');
295
- Joi.assert(params.query, Joi.object().required(), 'The query for the search');
296
- Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
297
- Joi.assert(session, Joi.string().required(), 'Session token JWT');
298
-
299
- const {query, orgId} = params;
300
- const queryString = JSON.stringify(query);
301
- const apiCall = self._client
302
- .get(`/organizations/${orgId}/process/export/status/data?query=${queryString}`, self._setHeader(session));
303
-
304
- return self._returnData(await apiCall);
305
- } catch (ex) {
306
- throw ex;
307
- }
308
- }
271
+ /**
272
+ * @author Myndware <augusto.pissarra@myndware.com>
273
+ * @description Method to export status data
274
+ * @param {object} params Params to export status data
275
+ * @param {object} params.query Search process query
276
+ * @param {object} params.orgId Organization id (_id database)
277
+ * @param {string} session Session, token JWT
278
+ * @public
279
+ * @example
280
+ *
281
+ * const API = require('@docbrasil/api-systemmanager');
282
+ * const api = new API();
283
+ * const params = {
284
+ * query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
285
+ * orgId: '55e4a3bd6be6b45210833fae',
286
+ * };
287
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
288
+ * const retSearch = await api.user.process.exportStatusData(params, session);
289
+ */
290
+ async exportStatusData(params, session) {
291
+ const self = this;
309
292
 
310
- /**
311
- * @author Myndware <augusto.pissarra@myndware.com>
312
- * @description Method to export process data
313
- * @param {object} params Params to export process data
314
- * @param {object} params.query Search process query
315
- * @param {object} params.orgId Organization id (_id database)
316
- * @param {string} session Session, token JWT
317
- * @public
318
- * @example
319
- *
320
- * const API = require('@docbrasil/api-systemmanager');
321
- * const api = new API();
322
- * const params = {
323
- * query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
324
- * orgId: '55e4a3bd6be6b45210833fae',
325
- * };
326
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
327
- * const retSearch = await api.user.process.exportProcessData(params, session);
328
- */
329
- async exportProcessData(params, session) {
330
- const self = this;
331
-
332
- try {
333
- Joi.assert(params, Joi.object().required(), 'Params to export process data');
334
- Joi.assert(params.query, Joi.object().required(), 'The query for the search');
335
- Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
336
- Joi.assert(session, Joi.string().required(), 'Session token JWT');
337
-
338
- const {query, orgId} = params;
339
- const queryString = JSON.stringify(query);
340
- const apiCall = self._client
341
- .get(`/organizations/${orgId}/process/export/collect/data?query=${queryString}`, self._setHeader(session));
342
-
343
- return self._returnData(await apiCall);
344
- } catch (ex) {
345
- throw ex;
346
- }
293
+ try {
294
+ Joi.assert(params, Joi.object().required(), 'Params to export status data');
295
+ Joi.assert(params.query, Joi.object().required(), 'The query for the search');
296
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
297
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
298
+
299
+ const {query, orgId} = params;
300
+ const queryString = JSON.stringify(query);
301
+ const apiCall = self._client
302
+ .get(`/organizations/${orgId}/process/export/status/data?query=${queryString}`, self._setHeader(session));
303
+
304
+ return self._returnData(await apiCall);
305
+ } catch (ex) {
306
+ throw ex;
347
307
  }
308
+ }
348
309
 
349
- /**
350
- * @author Myndware <augusto.pissarra@myndware.com>
351
- * @description Method to get Process Docs
352
- * @param {object} params Params to get process docs
353
- * @param {string} params.orgProcessId Organization Process Id
354
- * @param {string} params.processId Process Id
355
- * @param {string} params.orgId Organization id (_id database)
356
- * @param {string} session Session, token JWT
357
- * @returns {promise} returned data from the get process docs
358
- * @returns {array<object>} Docs returned from process
359
- * @public
360
- * @example
361
- *
362
- * const API = require('@docbrasil/api-systemmanager');
363
- * const api = new API();
364
- * const params = {
365
- * orgProcessId: '55e4a3bd6be6b45210833fae',
366
- * processId: '55e4a3bd6be6b45210833fae',
367
- * orgId: '55e4a3bd6be6b45210833fae',
368
- * };
369
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
370
- * const retSearch = await api.user.process.processDocs(params, session);
371
- */
372
- async processDocs(params, session) {
310
+ /**
311
+ * @author Myndware <augusto.pissarra@myndware.com>
312
+ * @description Method to export process data
313
+ * @param {object} params Params to export process data
314
+ * @param {object} params.query Search process query
315
+ * @param {object} params.orgId Organization id (_id database)
316
+ * @param {string} session Session, token JWT
317
+ * @public
318
+ * @example
319
+ *
320
+ * const API = require('@docbrasil/api-systemmanager');
321
+ * const api = new API();
322
+ * const params = {
323
+ * query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
324
+ * orgId: '55e4a3bd6be6b45210833fae',
325
+ * };
326
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
327
+ * const retSearch = await api.user.process.exportProcessData(params, session);
328
+ */
329
+ async exportProcessData(params, session) {
373
330
  const self = this;
374
331
 
375
332
  try {
376
- Joi.assert(params, Joi.object().required(), 'Params to get process docs');
377
- Joi.assert(params.orgProcessId, Joi.string().required(), 'Organization Process Id');
378
- Joi.assert(params.processId, Joi.string().required(), 'Process Id');
333
+ Joi.assert(params, Joi.object().required(), 'Params to export process data');
334
+ Joi.assert(params.query, Joi.object().required(), 'The query for the search');
379
335
  Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
380
336
  Joi.assert(session, Joi.string().required(), 'Session token JWT');
381
337
 
382
- const {orgProcessId, processId, orgId} = params;
383
- const apiCall = self._client.get(`/organizations/${orgId}/orgprocess/${orgProcessId}/process/${processId}/documents`, self._setHeader(session));
338
+ const {query, orgId} = params;
339
+ const queryString = JSON.stringify(query);
340
+ const apiCall = self._client
341
+ .get(`/organizations/${orgId}/process/export/collect/data?query=${queryString}`, self._setHeader(session));
342
+
384
343
  return self._returnData(await apiCall);
385
344
  } catch (ex) {
386
345
  throw ex;
@@ -388,65 +347,246 @@ class Process {
388
347
  }
389
348
 
390
349
  /**
391
- * @author Myndware <augusto.pissarra@myndware.com>
392
- * @description Method to download the process documents
393
- * @param {object} params Params to download the process documents
394
- * @param {string} params.orgId Organization id (_id database)
395
- * @param {string} params.type Document Type
396
- * @param {array} params.docIds Documents Ids
397
- * @param {string} params.footer Documents Footer
398
- * @param {string} session Session, token JWT
399
- * @returns {promise} returned data from the search
400
- * @public
401
- * @example
402
- *
403
- * const API = require('@docbrasil/api-systemmanager');
404
- * const api = new API();
405
- * const params = {
406
- * orgId: '55e4a3bd6be6b45210833fae',
407
- * type: 'Docs',
408
- * docIds: ['55e4a3bd6be6b45210833fae'],
409
- * footer: 'Documento - {page} de {pages}'
410
- * };
411
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
412
- * const result = await api.user.process.downloadDocs(params, session);
413
- */
350
+ * @author Myndware <augusto.pissarra@myndware.com>
351
+ * @description Method to get Process Docs
352
+ * @param {object} params Params to get process docs
353
+ * @param {string} params.orgProcessId Organization Process Id
354
+ * @param {string} params.processId Process Id
355
+ * @param {string} params.orgId Organization id (_id database)
356
+ * @param {string} session Session, token JWT
357
+ * @returns {promise} returned data from the get process docs
358
+ * @returns {array<object>} Docs returned from process
359
+ * @public
360
+ * @example
361
+ *
362
+ * const API = require('@docbrasil/api-systemmanager');
363
+ * const api = new API();
364
+ * const params = {
365
+ * orgProcessId: '55e4a3bd6be6b45210833fae',
366
+ * processId: '55e4a3bd6be6b45210833fae',
367
+ * orgId: '55e4a3bd6be6b45210833fae',
368
+ * };
369
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
370
+ * const retSearch = await api.user.process.processDocs(params, session);
371
+ */
372
+ async processDocs(params, session) {
373
+ const self = this;
374
+
375
+ try {
376
+ Joi.assert(params, Joi.object().required(), 'Params to get process docs');
377
+ Joi.assert(params.orgProcessId, Joi.string().required(), 'Organization Process Id');
378
+ Joi.assert(params.processId, Joi.string().required(), 'Process Id');
379
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
380
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
381
+
382
+ const {orgProcessId, processId, orgId} = params;
383
+ const apiCall = self._client.get(`/organizations/${orgId}/orgprocess/${orgProcessId}/process/${processId}/documents`, self._setHeader(session));
384
+ return self._returnData(await apiCall);
385
+ } catch (ex) {
386
+ throw ex;
387
+ }
388
+ }
389
+
390
+ /**
391
+ * @author Myndware <augusto.pissarra@myndware.com>
392
+ * @description Method to download the process documents
393
+ * @param {object} params Params to download the process documents
394
+ * @param {string} params.orgId Organization id (_id database)
395
+ * @param {string} params.type Document Type
396
+ * @param {array} params.docIds Documents Ids
397
+ * @param {string} params.footer Documents Footer
398
+ * @param {string} session Session, token JWT
399
+ * @returns {promise} returned data from the search
400
+ * @public
401
+ * @example
402
+ *
403
+ * const API = require('@docbrasil/api-systemmanager');
404
+ * const api = new API();
405
+ * const params = {
406
+ * orgId: '55e4a3bd6be6b45210833fae',
407
+ * type: 'Docs',
408
+ * docIds: ['55e4a3bd6be6b45210833fae'],
409
+ * footer: 'Documento - {page} de {pages}'
410
+ * };
411
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
412
+ * const result = await api.user.process.downloadDocs(params, session);
413
+ */
414
414
  async downloadDocs(params, session) {
415
+ const self = this;
416
+
417
+ try {
418
+ Joi.assert(params, Joi.object().required(), 'Params to download the process documents');
419
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
420
+ Joi.assert(params.type, Joi.string().required(), 'Document Type');
421
+ Joi.assert(params.docIds, Joi.array().required(), 'Document Ids');
422
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
423
+
424
+ const {orgId, type, docIds, footer} = params;
425
+ const data = {
426
+ docIds
427
+ };
428
+
429
+ if (footer) {
430
+ data.footer = footer
431
+ }
432
+
433
+ const apiCall = self._client
434
+ .post(`/organizations/${orgId}/documents/download/${type}`, data, self._setHeader(session));
435
+
436
+ return self._returnData(await apiCall);
437
+ } catch (ex) {
438
+ throw ex;
439
+ }
440
+ }
441
+
442
+ /**
443
+ * @author Myndware <augusto.pissarra@myndware.com>
444
+ * @description Get DocType properties of process
445
+ * @param {object} params Params to get document DocType
446
+ * @param {string} params.docTypeId Document DocTypeId id (_id database);
447
+ * @param {string} params.orgId Organization id (_id database);
448
+ * @param {string} session Session, token JWT
449
+ * @return {Promise}
450
+ * @public
451
+ * @async
452
+ * @example
453
+ *
454
+ * const API = require('@docbrasil/api-systemmanager');
455
+ * const api = new API();
456
+ * const params = {
457
+ * docTypeId: '5dadd01dc4af3941d42f8c5c',
458
+ * orgId: '5edd11c46b6ce9729c2c297c',
459
+ * }
460
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
461
+ * await api.user.process.getOrgDocTypes(params, session);
462
+ */
463
+ async getOrgDocTypes(params, session) {
415
464
  const self = this;
416
465
 
417
466
  try {
418
- Joi.assert(params, Joi.object().required(), 'Params to download the process documents');
419
- Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
420
- Joi.assert(params.type, Joi.string().required(), 'Document Type');
421
- Joi.assert(params.docIds, Joi.array().required(), 'Document Ids');
422
- Joi.assert(session, Joi.string().required(), 'Session token JWT');
467
+ Joi.assert(params, Joi.object().required());
468
+ Joi.assert(params.docTypeId, Joi.string().required());
469
+ Joi.assert(params.orgId, Joi.string().required());
470
+ Joi.assert(session, Joi.string().required());
471
+
472
+ const {docTypeId, orgId} = params;
473
+ const apiCall = self._client.get(`/organizations/${orgId}/doctype/${docTypeId}`, self._setHeader(session));
474
+ return self._returnData(await apiCall);
475
+ } catch (ex) {
476
+ throw ex;
477
+ }
478
+ }
423
479
 
424
- const {orgId, type, docIds, footer} = params;
425
- const data = {
426
- docIds
427
- };
480
+ /**
481
+ * @author Myndware <augusto.pissarra@myndware.com>
482
+ * @description Get Org Groups
483
+ * @param {object} params Params to get Org Groups
484
+ * @param {string} params.orgId Organization id (_id database);
485
+ * @param {string} session Session, token JWT
486
+ * @return {Promise}
487
+ * @public
488
+ * @async
489
+ * @example
490
+ *
491
+ * const API = require('@docbrasil/api-systemmanager');
492
+ * const api = new API();
493
+ * const params = {
494
+ * orgId: '5edd11c46b6ce9729c2c297c',
495
+ * }
496
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
497
+ * await api.user.process.getOrgGroups(params, session);
498
+ */
499
+ async getOrgGroups(params, session) {
500
+ const self = this;
428
501
 
429
- if (footer) {
430
- data.footer = footer
431
- }
502
+ try {
503
+ Joi.assert(params, Joi.object().required());
504
+ Joi.assert(params.orgId, Joi.string().required());
505
+ Joi.assert(session, Joi.string().required());
432
506
 
433
- const apiCall = self._client
434
- .post(`/organizations/${orgId}/documents/download/${type}`, data, self._setHeader(session));
507
+ const {orgId} = params;
508
+ const apiCall = self._client.get(`/organizations/${orgId}/groups`, self._setHeader(session));
509
+ return self._returnData(await apiCall);
510
+ } catch (ex) {
511
+ throw ex;
512
+ }
513
+ }
514
+
515
+ /**
516
+ * @author Myndware <augusto.pissarra@myndware.com>
517
+ * @description Get Org Users
518
+ * @param {object} params Params to get Org Users
519
+ * @param {string} params.orgId Organization id (_id database);
520
+ * @param {array} params.userIds UserIds
521
+ * @param {string} session Session, token JWT
522
+ * @return {Promise}
523
+ * @public
524
+ * @async
525
+ * @example
526
+ *
527
+ * const API = require('@docbrasil/api-systemmanager');
528
+ * const api = new API();
529
+ * const params = {
530
+ * orgId: '5edd11c46b6ce9729c2c297c',
531
+ * userIds: []
532
+ * }
533
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
534
+ * await api.user.process.getOrgUsers(params, session);
535
+ */
536
+ async getOrgUsers(params, session) {
537
+ const self = this;
435
538
 
539
+ try {
540
+ Joi.assert(params, Joi.object().required());
541
+ Joi.assert(params.orgId, Joi.string().required());
542
+ Joi.assert(params.userIds, Joi.array().required());
543
+ Joi.assert(session, Joi.string().required());
544
+
545
+ const {orgId, userIds} = params;
546
+ let queryString = '';
547
+ if(!_.isEmpty(userIds)) {
548
+ queryString = `?userIds=${JSON.stringify(userIds)}&{"sort":{"name":1}}`;
549
+ }
550
+ const apiCall = self._client.get(`/admin/organizations/${orgId}/orgusers${queryString}`, self._setHeader(session));
436
551
  return self._returnData(await apiCall);
437
552
  } catch (ex) {
438
553
  throw ex;
439
554
  }
440
555
  }
441
556
 
557
+ /**
558
+ * @author Myndware <augusto.pissarra@myndware.com>
559
+ * @description Get step history of a process flow
560
+ * @param {object} params Params to get step history
561
+ * @param {string} params.orgId Organization id (_id database);
562
+ * @param {string} params.processId Process id (_id database);
563
+ * @param {string} params.flowId Flow id;
564
+ * @param {string} session Session, token JWT
565
+ * @return {Promise<Array>} Array of step history entries
566
+ * @public
567
+ * @async
568
+ * @example
569
+ *
570
+ * const API = require('@docbrasil/api-systemmanager');
571
+ * const api = new API();
572
+ * const params = {
573
+ * orgId: '5edd11c46b6ce9729c2c297c',
574
+ * processId: '5dadd01dc4af3941d42f8c5c',
575
+ * flowId: 'Task_18v1xx7'
576
+ * }
577
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
578
+ * const stepHistory = await api.user.process.getStepHistory(params, session);
579
+ */
442
580
  /**
443
581
  * @author Myndware <augusto.pissarra@myndware.com>
444
- * @description Get DocType properties of process
445
- * @param {object} params Params to get document DocType
446
- * @param {string} params.docTypeId Document DocTypeId id (_id database);
582
+ * @description Restart a finished process from a specific flow step. Resets the process completion state
583
+ * and triggers re-execution from the specified flow name.
584
+ * @param {object} params Params to restart the process
585
+ * @param {string} params.processId Process id (_id database);
447
586
  * @param {string} params.orgId Organization id (_id database);
587
+ * @param {string} params.flowName The flow name of the step to restart from;
448
588
  * @param {string} session Session, token JWT
449
- * @return {Promise}
589
+ * @return {Promise<object>} { response: 'OK' } on success
450
590
  * @public
451
591
  * @async
452
592
  * @example
@@ -454,36 +594,41 @@ class Process {
454
594
  * const API = require('@docbrasil/api-systemmanager');
455
595
  * const api = new API();
456
596
  * const params = {
457
- * docTypeId: '5dadd01dc4af3941d42f8c5c',
597
+ * processId: '5dadd01dc4af3941d42f8c5c',
458
598
  * orgId: '5edd11c46b6ce9729c2c297c',
459
- * }
599
+ * flowName: 'Task_1'
600
+ * };
460
601
  * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
461
- * await api.user.process.getOrgDocTypes(params, session);
602
+ * await api.user.process.restart(params, session);
462
603
  */
463
- async getOrgDocTypes(params, session) {
464
- const self = this;
465
-
466
- try {
467
- Joi.assert(params, Joi.object().required());
468
- Joi.assert(params.docTypeId, Joi.string().required());
469
- Joi.assert(params.orgId, Joi.string().required());
470
- Joi.assert(session, Joi.string().required());
471
-
472
- const {docTypeId, orgId} = params;
473
- const apiCall = self._client.get(`/organizations/${orgId}/doctype/${docTypeId}`, self._setHeader(session));
474
- return self._returnData(await apiCall);
475
- } catch (ex) {
476
- throw ex;
477
- }
604
+ async restart(params, session) {
605
+ const self = this;
606
+
607
+ try {
608
+ Joi.assert(params, Joi.object().required(), 'Params to restart the process');
609
+ Joi.assert(params.processId, Joi.string().required(), 'Process id (_id database)');
610
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
611
+ Joi.assert(params.flowName, Joi.string().required(), 'Flow name of the step');
612
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
613
+
614
+ const {processId, orgId, flowName} = params;
615
+ const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}/restart/${flowName}`, {}, self._setHeader(session));
616
+ return self._returnData(await apiCall);
617
+ } catch (ex) {
618
+ throw ex;
478
619
  }
620
+ }
479
621
 
480
- /**
622
+ /**
481
623
  * @author Myndware <augusto.pissarra@myndware.com>
482
- * @description Get Org Groups
483
- * @param {object} params Params to get Org Groups
624
+ * @description Re-execute a specific flow step in a running process. Unlike restart, this does not
625
+ * reset the process completion state. Task creation is deferred to the BPMN engine via RabbitMQ.
626
+ * @param {object} params Params to re-execute the process step
627
+ * @param {string} params.processId Process id (_id database);
484
628
  * @param {string} params.orgId Organization id (_id database);
629
+ * @param {string} params.flowName The flow name of the step to re-execute;
485
630
  * @param {string} session Session, token JWT
486
- * @return {Promise}
631
+ * @return {Promise<object>} { response: 'OK' } on success
487
632
  * @public
488
633
  * @async
489
634
  * @example
@@ -491,35 +636,42 @@ class Process {
491
636
  * const API = require('@docbrasil/api-systemmanager');
492
637
  * const api = new API();
493
638
  * const params = {
639
+ * processId: '5dadd01dc4af3941d42f8c5c',
494
640
  * orgId: '5edd11c46b6ce9729c2c297c',
495
- * }
641
+ * flowName: 'Task_1'
642
+ * };
496
643
  * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
497
- * await api.user.process.getOrgGroups(params, session);
644
+ * await api.user.process.reexecute(params, session);
498
645
  */
499
- async getOrgGroups(params, session) {
500
- const self = this;
501
-
502
- try {
503
- Joi.assert(params, Joi.object().required());
504
- Joi.assert(params.orgId, Joi.string().required());
505
- Joi.assert(session, Joi.string().required());
506
-
507
- const {orgId} = params;
508
- const apiCall = self._client.get(`/organizations/${orgId}/groups`, self._setHeader(session));
509
- return self._returnData(await apiCall);
510
- } catch (ex) {
511
- throw ex;
512
- }
646
+ async reexecute(params, session) {
647
+ const self = this;
648
+
649
+ try {
650
+ Joi.assert(params, Joi.object().required(), 'Params to re-execute the process step');
651
+ Joi.assert(params.processId, Joi.string().required(), 'Process id (_id database)');
652
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
653
+ Joi.assert(params.flowName, Joi.string().required(), 'Flow name of the step');
654
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
655
+
656
+ const {processId, orgId, flowName} = params;
657
+ const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}/reexecute/${flowName}`, {}, self._setHeader(session));
658
+ return self._returnData(await apiCall);
659
+ } catch (ex) {
660
+ throw ex;
513
661
  }
662
+ }
514
663
 
515
- /**
664
+ /**
516
665
  * @author Myndware <augusto.pissarra@myndware.com>
517
- * @description Get Org Users
518
- * @param {object} params Params to get Org Users
666
+ * @description Re-execute a specific user task step in a running process, creating a new task
667
+ * synchronously with optional userId reassignment. For non-group tasks, the task is reassigned
668
+ * to the current logged-in user. For group tasks, the original assignment is preserved.
669
+ * @param {object} params Params to re-execute the task
670
+ * @param {string} params.processId Process id (_id database);
519
671
  * @param {string} params.orgId Organization id (_id database);
520
- * @param {array} params.userIds UserIds
672
+ * @param {string} params.flowName The flow name of the user task step to re-execute;
521
673
  * @param {string} session Session, token JWT
522
- * @return {Promise}
674
+ * @return {Promise<object>} { response: 'OK', taskId } on success
523
675
  * @public
524
676
  * @async
525
677
  * @example
@@ -527,73 +679,49 @@ class Process {
527
679
  * const API = require('@docbrasil/api-systemmanager');
528
680
  * const api = new API();
529
681
  * const params = {
682
+ * processId: '5dadd01dc4af3941d42f8c5c',
530
683
  * orgId: '5edd11c46b6ce9729c2c297c',
531
- * userIds: []
532
- * }
684
+ * flowName: 'Task_1'
685
+ * };
533
686
  * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
534
- * await api.user.process.getOrgUsers(params, session);
687
+ * const result = await api.user.process.reexecuteTask(params, session);
688
+ * console.log(result.taskId);
535
689
  */
536
- async getOrgUsers(params, session) {
537
- const self = this;
538
-
539
- try {
540
- Joi.assert(params, Joi.object().required());
541
- Joi.assert(params.orgId, Joi.string().required());
542
- Joi.assert(params.userIds, Joi.array().required());
543
- Joi.assert(session, Joi.string().required());
544
-
545
- const {orgId, userIds} = params;
546
- let queryString = '';
547
- if(!_.isEmpty(userIds)) {
548
- queryString = `?userIds=${JSON.stringify(userIds)}&{"sort":{"name":1}}`;
549
- }
550
- const apiCall = self._client.get(`/admin/organizations/${orgId}/orgusers${queryString}`, self._setHeader(session));
551
- return self._returnData(await apiCall);
552
- } catch (ex) {
553
- throw ex;
554
- }
690
+ async reexecuteTask(params, session) {
691
+ const self = this;
692
+
693
+ try {
694
+ Joi.assert(params, Joi.object().required(), 'Params to re-execute the task');
695
+ Joi.assert(params.processId, Joi.string().required(), 'Process id (_id database)');
696
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
697
+ Joi.assert(params.flowName, Joi.string().required(), 'Flow name of the user task step');
698
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
699
+
700
+ const {processId, orgId, flowName} = params;
701
+ const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}/reexecutetask/${flowName}`, {}, self._setHeader(session));
702
+ return self._returnData(await apiCall);
703
+ } catch (ex) {
704
+ throw ex;
555
705
  }
706
+ }
556
707
 
557
- /**
558
- * @author Myndware <augusto.pissarra@myndware.com>
559
- * @description Get step history of a process flow
560
- * @param {object} params Params to get step history
561
- * @param {string} params.orgId Organization id (_id database);
562
- * @param {string} params.processId Process id (_id database);
563
- * @param {string} params.flowId Flow id;
564
- * @param {string} session Session, token JWT
565
- * @return {Promise<Array>} Array of step history entries
566
- * @public
567
- * @async
568
- * @example
569
- *
570
- * const API = require('@docbrasil/api-systemmanager');
571
- * const api = new API();
572
- * const params = {
573
- * orgId: '5edd11c46b6ce9729c2c297c',
574
- * processId: '5dadd01dc4af3941d42f8c5c',
575
- * flowId: 'Task_18v1xx7'
576
- * }
577
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
578
- * const stepHistory = await api.user.process.getStepHistory(params, session);
579
- */
580
- async getStepHistory(params, session) {
581
- const self = this;
582
-
583
- try {
584
- Joi.assert(params, Joi.object().required());
585
- Joi.assert(params.orgId, Joi.string().required());
586
- Joi.assert(params.processId, Joi.string().required());
587
- Joi.assert(params.flowId, Joi.string().required());
588
- Joi.assert(session, Joi.string().required());
589
-
590
- const {orgId, processId, flowId} = params;
591
- const apiCall = self._client.get(`/organizations/${orgId}/process/${processId}/flow/${flowId}/history`, self._setHeader(session));
592
- return self._returnData(await apiCall, []);
593
- } catch (ex) {
594
- throw ex;
595
- }
708
+ async getStepHistory(params, session) {
709
+ const self = this;
710
+
711
+ try {
712
+ Joi.assert(params, Joi.object().required());
713
+ Joi.assert(params.orgId, Joi.string().required());
714
+ Joi.assert(params.processId, Joi.string().required());
715
+ Joi.assert(params.flowId, Joi.string().required());
716
+ Joi.assert(session, Joi.string().required());
717
+
718
+ const {orgId, processId, flowId} = params;
719
+ const apiCall = self._client.get(`/organizations/${orgId}/process/${processId}/flow/${flowId}/history`, self._setHeader(session));
720
+ return self._returnData(await apiCall, []);
721
+ } catch (ex) {
722
+ throw ex;
596
723
  }
724
+ }
597
725
  }
598
726
 
599
727
  export default Process;