@steedos-labs/content-compliance 0.7.3 → 0.7.5

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.
@@ -499,20 +499,20 @@ var updateUserStepStatus = function (ctx, materialApproval, _a) {
499
499
  });
500
500
  };
501
501
  var updateApproveFieldStatus = function (ctx, recordId, approveField, approveFieldValue) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
502
- var userId, set, approvalNew, approvals, index;
503
- var _a;
504
- return tslib_1.__generator(this, function (_b) {
505
- switch (_b.label) {
502
+ var userId, set, approvalNew, approvals, index, postponedUsers, postponeRecords, postponeRecords_1, postponeRecords_1_1, pr, prUserIds, e_3_1;
503
+ var _a, e_3, _b;
504
+ return tslib_1.__generator(this, function (_c) {
505
+ switch (_c.label) {
506
506
  case 0:
507
507
  userId = ctx.meta.user.userId;
508
- if (!approveField) return [3, 4];
508
+ if (!approveField) return [3, 13];
509
509
  set = (_a = {},
510
510
  _a[approveField] = approveFieldValue,
511
511
  _a);
512
- if (!userId) return [3, 2];
512
+ if (!userId) return [3, 11];
513
513
  return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
514
514
  case 1:
515
- approvalNew = _b.sent();
515
+ approvalNew = _c.sent();
516
516
  approvals = approvalNew.person_pending_approve || [];
517
517
  index = (0, lodash_1.findIndex)(approvals, function (item) { return item === userId; });
518
518
  if (index !== -1) {
@@ -522,22 +522,66 @@ var updateApproveFieldStatus = function (ctx, recordId, approveField, approveFie
522
522
  set.$push = {
523
523
  person_approved: userId
524
524
  };
525
- _b.label = 2;
525
+ postponedUsers = approvalNew.review_postponed_users || [];
526
+ if (!postponedUsers.includes(userId)) return [3, 11];
527
+ set.review_postponed_users = postponedUsers.filter(function (uid) { return uid !== userId; });
528
+ return [4, ctx.getObject('pepsico_review_postpone').directFind({
529
+ filters: [
530
+ ['pepsico_material_approval', '=', recordId],
531
+ ['notification_sent', '=', false],
532
+ ['is_marker', '!=', true]
533
+ ]
534
+ })];
526
535
  case 2:
536
+ postponeRecords = _c.sent();
537
+ _c.label = 3;
538
+ case 3:
539
+ _c.trys.push([3, 8, 9, 10]);
540
+ postponeRecords_1 = tslib_1.__values(postponeRecords), postponeRecords_1_1 = postponeRecords_1.next();
541
+ _c.label = 4;
542
+ case 4:
543
+ if (!!postponeRecords_1_1.done) return [3, 7];
544
+ pr = postponeRecords_1_1.value;
545
+ prUserIds = pr.postponed_user_ids ? pr.postponed_user_ids.split(',').filter(Boolean) : [];
546
+ if (!prUserIds.includes(userId)) return [3, 6];
547
+ return [4, ctx.getObject('pepsico_review_postpone').directUpdate(pr._id, {
548
+ notification_sent: true
549
+ })];
550
+ case 5:
551
+ _c.sent();
552
+ _c.label = 6;
553
+ case 6:
554
+ postponeRecords_1_1 = postponeRecords_1.next();
555
+ return [3, 4];
556
+ case 7: return [3, 10];
557
+ case 8:
558
+ e_3_1 = _c.sent();
559
+ e_3 = { error: e_3_1 };
560
+ return [3, 10];
561
+ case 9:
562
+ try {
563
+ if (postponeRecords_1_1 && !postponeRecords_1_1.done && (_b = postponeRecords_1.return)) _b.call(postponeRecords_1);
564
+ }
565
+ finally { if (e_3) throw e_3.error; }
566
+ return [7];
567
+ case 10:
568
+ console.log("[updateApproveFieldStatus] \u5EF6\u540E\u5BA1\u6838\u4EBA\u63D0\u524D\u5BA1\u6838\uFF0C\u5DF2\u6E05\u7406 review_postponed_users: ".concat(userId));
569
+ _c.label = 11;
570
+ case 11:
527
571
  console.log('[updateApproveFieldStatus]', JSON.stringify({ recordId: recordId, set: set }));
528
572
  return [4, ctx.getObject('pepsico_material_approval').update(recordId, set)];
529
- case 3:
530
- _b.sent();
531
- _b.label = 4;
532
- case 4: return [2];
573
+ case 12:
574
+ _c.sent();
575
+ _c.label = 13;
576
+ case 13: return [2];
533
577
  }
534
578
  });
535
579
  }); };
536
580
  var changeApprovalProcess = function (ctx, materialApproval, _a) {
537
581
  var nextStep = _a.nextStep, nextApprovers = _a.nextApprovers, description = _a.description;
538
582
  return tslib_1.__awaiter(void 0, void 0, void 0, function () {
539
- var user, count, now, sUsers, _b, nextApprovers_1, nextApprovers_1_1, nextApprover, _c, _d, userId, spaceUsers, e_3_1, e_4_1;
540
- var e_4, _e, e_3, _f, _g;
583
+ var user, count, now, sUsers, _b, nextApprovers_1, nextApprovers_1_1, nextApprover, _c, _d, userId, spaceUsers, e_4_1, e_5_1;
584
+ var e_5, _e, e_4, _f, _g;
541
585
  return tslib_1.__generator(this, function (_h) {
542
586
  switch (_h.label) {
543
587
  case 0:
@@ -594,7 +638,7 @@ var changeApprovalProcess = function (ctx, materialApproval, _a) {
594
638
  _h.label = 6;
595
639
  case 6:
596
640
  _h.trys.push([6, 12, 13, 14]);
597
- _c = (e_3 = void 0, tslib_1.__values(nextApprover.userIds)), _d = _c.next();
641
+ _c = (e_4 = void 0, tslib_1.__values(nextApprover.userIds)), _d = _c.next();
598
642
  _h.label = 7;
599
643
  case 7:
600
644
  if (!!_d.done) return [3, 11];
@@ -624,14 +668,14 @@ var changeApprovalProcess = function (ctx, materialApproval, _a) {
624
668
  return [3, 7];
625
669
  case 11: return [3, 14];
626
670
  case 12:
627
- e_3_1 = _h.sent();
628
- e_3 = { error: e_3_1 };
671
+ e_4_1 = _h.sent();
672
+ e_4 = { error: e_4_1 };
629
673
  return [3, 14];
630
674
  case 13:
631
675
  try {
632
676
  if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
633
677
  }
634
- finally { if (e_3) throw e_3.error; }
678
+ finally { if (e_4) throw e_4.error; }
635
679
  return [7];
636
680
  case 14:
637
681
  if (!nextApprover.type) return [3, 16];
@@ -646,14 +690,14 @@ var changeApprovalProcess = function (ctx, materialApproval, _a) {
646
690
  return [3, 5];
647
691
  case 17: return [3, 20];
648
692
  case 18:
649
- e_4_1 = _h.sent();
650
- e_4 = { error: e_4_1 };
693
+ e_5_1 = _h.sent();
694
+ e_5 = { error: e_5_1 };
651
695
  return [3, 20];
652
696
  case 19:
653
697
  try {
654
698
  if (nextApprovers_1_1 && !nextApprovers_1_1.done && (_e = nextApprovers_1.return)) _e.call(nextApprovers_1);
655
699
  }
656
- finally { if (e_4) throw e_4.error; }
700
+ finally { if (e_5) throw e_5.error; }
657
701
  return [7];
658
702
  case 20: return [3, 24];
659
703
  case 21: return [4, ctx.getObject('pepsico_approval_process').insert({
@@ -725,8 +769,8 @@ var PRE_TO_FORMAL_MAPPING = {
725
769
  'pre_approval_status': { reviewerField: 'reviewer', type: consts_1.ProcessApprovalType.guding, statusField: 'approval_status' },
726
770
  };
727
771
  var addFormalReviewerAfterPreApproval = function (ctx, recordId, approveField, materialApproval) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
728
- var info, formalStatus, reviewerIds, userIds, agents, user, _a, _b, userId, spaceUsers, e_5_1, currentApproval, pendingApprove, newPending;
729
- var e_5, _c, _d, _e, _f;
772
+ var info, formalStatus, reviewerIds, userIds, agents, user, _a, _b, userId, spaceUsers, e_6_1, currentApproval, pendingApprove, newPending;
773
+ var e_6, _c, _d, _e, _f;
730
774
  return tslib_1.__generator(this, function (_g) {
731
775
  switch (_g.label) {
732
776
  case 0:
@@ -779,14 +823,14 @@ var addFormalReviewerAfterPreApproval = function (ctx, recordId, approveField, m
779
823
  return [3, 3];
780
824
  case 7: return [3, 10];
781
825
  case 8:
782
- e_5_1 = _g.sent();
783
- e_5 = { error: e_5_1 };
826
+ e_6_1 = _g.sent();
827
+ e_6 = { error: e_6_1 };
784
828
  return [3, 10];
785
829
  case 9:
786
830
  try {
787
831
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
788
832
  }
789
- finally { if (e_5) throw e_5.error; }
833
+ finally { if (e_6) throw e_6.error; }
790
834
  return [7];
791
835
  case 10: return [4, ctx.getObject('pepsico_material_approval').directUpdate(materialApproval._id, (_d = {},
792
836
  _d["handler_".concat((0, lodash_1.toLower)(info.type))] = agents.userIds,
@@ -847,8 +891,8 @@ var hasNonPreReviewDepartments = function (materialApproval) {
847
891
  };
848
892
  exports.hasNonPreReviewDepartments = hasNonPreReviewDepartments;
849
893
  var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
850
- var actionLabel, user, record, nextStep, skipApprover, nextApprovers, _nextApprovers, nextApprovers_2, nextApprovers_2_1, reviewer, fieldName, status, e_6_1, nextApproversUserIds_1, nextApproversClientUserIds_1, setDoc, nextApprovers_3, nextApprovers_3_1, nextApprover, e_7_1, setDoc_1, postponedUserIds_1, now, visibleAfter, pastPostponeRecords, postponedDepts, _loop_1, nextApprovers_4, nextApprovers_4_1, reviewer, e_8_1, currentRecord, currentPostponed, newPostponed, notifyUserIds, initiator, materialOwner, error_1;
851
- var e_6, _a, _b, _c, e_7, _d, e_8, _e;
894
+ var actionLabel, user, record, nextStep, skipApprover, nextApprovers, _nextApprovers, nextApprovers_2, nextApprovers_2_1, reviewer, fieldName, status, e_7_1, nextApproversUserIds_1, nextApproversClientUserIds_1, setDoc, nextApprovers_3, nextApprovers_3_1, nextApprover, e_8_1, setDoc_1, postponedUserIds_1, now, visibleAfter, pastPostponeRecords, postponedDepts, _loop_1, nextApprovers_4, nextApprovers_4_1, reviewer, e_9_1, currentRecord, currentPostponed, newPostponed, currentMarkerUsers, newMarkerUsers, notifyUserIds, initiator, materialOwner, error_1;
895
+ var e_7, _a, _b, _c, e_8, _d, e_9, _e;
852
896
  return tslib_1.__generator(this, function (_f) {
853
897
  switch (_f.label) {
854
898
  case 0:
@@ -931,14 +975,14 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
931
975
  return [3, 11];
932
976
  case 17: return [3, 20];
933
977
  case 18:
934
- e_6_1 = _f.sent();
935
- e_6 = { error: e_6_1 };
978
+ e_7_1 = _f.sent();
979
+ e_7 = { error: e_7_1 };
936
980
  return [3, 20];
937
981
  case 19:
938
982
  try {
939
983
  if (nextApprovers_2_1 && !nextApprovers_2_1.done && (_a = nextApprovers_2.return)) _a.call(nextApprovers_2);
940
984
  }
941
- finally { if (e_6) throw e_6.error; }
985
+ finally { if (e_7) throw e_7.error; }
942
986
  return [7];
943
987
  case 20:
944
988
  if (!(_nextApprovers.length > 0)) return [3, 21];
@@ -1187,14 +1231,14 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
1187
1231
  return [3, 34];
1188
1232
  case 68: return [3, 71];
1189
1233
  case 69:
1190
- e_7_1 = _f.sent();
1191
- e_7 = { error: e_7_1 };
1234
+ e_8_1 = _f.sent();
1235
+ e_8 = { error: e_8_1 };
1192
1236
  return [3, 71];
1193
1237
  case 70:
1194
1238
  try {
1195
1239
  if (nextApprovers_3_1 && !nextApprovers_3_1.done && (_d = nextApprovers_3.return)) _d.call(nextApprovers_3);
1196
1240
  }
1197
- finally { if (e_7) throw e_7.error; }
1241
+ finally { if (e_8) throw e_8.error; }
1198
1242
  return [7];
1199
1243
  case 71:
1200
1244
  if (!(nextStep === consts_1.Step.departmental_review || nextStep === consts_1.Step.personnel_review)) return [3, 73];
@@ -1251,8 +1295,8 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
1251
1295
  if (!(pastPostponeRecords && pastPostponeRecords.length > 0)) return [3, 91];
1252
1296
  postponedDepts = new Set(pastPostponeRecords.map(function (r) { return r.department_type; }));
1253
1297
  _loop_1 = function (reviewer) {
1254
- var deptUserIds, deptMarkers, deptMarkers_1, deptMarkers_1_1, marker, e_9_1;
1255
- var e_9, _g;
1298
+ var deptUserIds, deptMarkers, deptMarkers_1, deptMarkers_1_1, marker, e_10_1;
1299
+ var e_10, _g;
1256
1300
  return tslib_1.__generator(this, function (_h) {
1257
1301
  switch (_h.label) {
1258
1302
  case 0:
@@ -1263,7 +1307,7 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
1263
1307
  _h.label = 1;
1264
1308
  case 1:
1265
1309
  _h.trys.push([1, 6, 7, 8]);
1266
- deptMarkers_1 = (e_9 = void 0, tslib_1.__values(deptMarkers)), deptMarkers_1_1 = deptMarkers_1.next();
1310
+ deptMarkers_1 = (e_10 = void 0, tslib_1.__values(deptMarkers)), deptMarkers_1_1 = deptMarkers_1.next();
1267
1311
  _h.label = 2;
1268
1312
  case 2:
1269
1313
  if (!!deptMarkers_1_1.done) return [3, 5];
@@ -1284,14 +1328,14 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
1284
1328
  return [3, 2];
1285
1329
  case 5: return [3, 8];
1286
1330
  case 6:
1287
- e_9_1 = _h.sent();
1288
- e_9 = { error: e_9_1 };
1331
+ e_10_1 = _h.sent();
1332
+ e_10 = { error: e_10_1 };
1289
1333
  return [3, 8];
1290
1334
  case 7:
1291
1335
  try {
1292
1336
  if (deptMarkers_1_1 && !deptMarkers_1_1.done && (_g = deptMarkers_1.return)) _g.call(deptMarkers_1);
1293
1337
  }
1294
- finally { if (e_9) throw e_9.error; }
1338
+ finally { if (e_10) throw e_10.error; }
1295
1339
  return [7];
1296
1340
  case 8:
1297
1341
  postponedUserIds_1 = (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.concat)(postponedUserIds_1, deptUserIds)));
@@ -1316,14 +1360,14 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
1316
1360
  return [3, 82];
1317
1361
  case 85: return [3, 88];
1318
1362
  case 86:
1319
- e_8_1 = _f.sent();
1320
- e_8 = { error: e_8_1 };
1363
+ e_9_1 = _f.sent();
1364
+ e_9 = { error: e_9_1 };
1321
1365
  return [3, 88];
1322
1366
  case 87:
1323
1367
  try {
1324
1368
  if (nextApprovers_4_1 && !nextApprovers_4_1.done && (_e = nextApprovers_4.return)) _e.call(nextApprovers_4);
1325
1369
  }
1326
- finally { if (e_8) throw e_8.error; }
1370
+ finally { if (e_9) throw e_9.error; }
1327
1371
  return [7];
1328
1372
  case 88:
1329
1373
  if (!(postponedUserIds_1.length > 0)) return [3, 91];
@@ -1332,8 +1376,11 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
1332
1376
  currentRecord = _f.sent();
1333
1377
  currentPostponed = currentRecord.review_postponed_users || [];
1334
1378
  newPostponed = (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.concat)(currentPostponed, postponedUserIds_1)));
1379
+ currentMarkerUsers = currentRecord.postpone_marker_users || [];
1380
+ newMarkerUsers = currentMarkerUsers.filter(function (uid) { return !postponedUserIds_1.includes(uid); });
1335
1381
  return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
1336
- review_postponed_users: newPostponed
1382
+ review_postponed_users: newPostponed,
1383
+ postpone_marker_users: newMarkerUsers
1337
1384
  })];
1338
1385
  case 90:
1339
1386
  _f.sent();
@@ -1366,8 +1413,8 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
1366
1413
  }); };
1367
1414
  exports.advanceApproval = advanceApproval;
1368
1415
  var terminate = function (ctx, recordId, description) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
1369
- var user, record, records, records_1, records_1_1, process_2, e_10_1;
1370
- var e_10, _a;
1416
+ var user, record, records, records_1, records_1_1, process_2, e_11_1;
1417
+ var e_11, _a;
1371
1418
  return tslib_1.__generator(this, function (_b) {
1372
1419
  switch (_b.label) {
1373
1420
  case 0:
@@ -1416,14 +1463,14 @@ var terminate = function (ctx, recordId, description) { return tslib_1.__awaiter
1416
1463
  return [3, 5];
1417
1464
  case 8: return [3, 11];
1418
1465
  case 9:
1419
- e_10_1 = _b.sent();
1420
- e_10 = { error: e_10_1 };
1466
+ e_11_1 = _b.sent();
1467
+ e_11 = { error: e_11_1 };
1421
1468
  return [3, 11];
1422
1469
  case 10:
1423
1470
  try {
1424
1471
  if (records_1_1 && !records_1_1.done && (_a = records_1.return)) _a.call(records_1);
1425
1472
  }
1426
- finally { if (e_10) throw e_10.error; }
1473
+ finally { if (e_11) throw e_11.error; }
1427
1474
  return [7];
1428
1475
  case 11: return [4, ctx.getObject('pepsico_material_approval').update(recordId, {
1429
1476
  current_step: consts_1.Step.conclusion,
@@ -1779,8 +1826,8 @@ var submitPreReviewContent = function (ctx, recordId, currentStepApprovalStatus)
1779
1826
  exports.submitPreReviewContent = submitPreReviewContent;
1780
1827
  var submitContent = function (ctx, recordId, currentStepApprovalStatus, skip) {
1781
1828
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1782
- var approvalNew, user, allow, aProcess, aProcess_1, aProcess_1_1, item, e_11_1, approvalType, allTrue1, allTrue, spaceUsers, owner, materials, pendingXmlToWordMaterials, pendingUploadMaterials;
1783
- var e_11, _a;
1829
+ var approvalNew, user, allow, aProcess, aProcess_1, aProcess_1_1, item, e_12_1, approvalType, allTrue1, allTrue, spaceUsers, owner, materials, pendingXmlToWordMaterials, pendingUploadMaterials;
1830
+ var e_12, _a;
1784
1831
  return tslib_1.__generator(this, function (_b) {
1785
1832
  switch (_b.label) {
1786
1833
  case 0: return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
@@ -1838,14 +1885,14 @@ var submitContent = function (ctx, recordId, currentStepApprovalStatus, skip) {
1838
1885
  return [3, 4];
1839
1886
  case 7: return [3, 10];
1840
1887
  case 8:
1841
- e_11_1 = _b.sent();
1842
- e_11 = { error: e_11_1 };
1888
+ e_12_1 = _b.sent();
1889
+ e_12 = { error: e_12_1 };
1843
1890
  return [3, 10];
1844
1891
  case 9:
1845
1892
  try {
1846
1893
  if (aProcess_1_1 && !aProcess_1_1.done && (_a = aProcess_1.return)) _a.call(aProcess_1);
1847
1894
  }
1848
- finally { if (e_11) throw e_11.error; }
1895
+ finally { if (e_12) throw e_12.error; }
1849
1896
  return [7];
1850
1897
  case 10:
1851
1898
  if (allow != true && approvalNew.current_step != consts_1.Step.draft && !(0, lodash_1.includes)(approvalNew.person_pending_approve, user.userId)) {
@@ -2009,8 +2056,8 @@ var TYPE_TO_REVIEWER_FIELD = (_a = {},
2009
2056
  _a);
2010
2057
  var postponeReview = function (ctx, recordId, data) {
2011
2058
  return tslib_1.__awaiter(this, void 0, void 0, function () {
2012
- var user, record, progessRecords, userProcessRecords, departmentType, reviewerField, deptUserIds, val, now, unactivatedMarkers, latestMarker, _a, _b, marker, e_12_1;
2013
- var e_12, _c;
2059
+ var user, record, progessRecords, userProcessRecords, departmentType, reviewerField, deptUserIds, val, now, unactivatedMarkers, latestMarker, _a, _b, marker, e_13_1;
2060
+ var e_13, _c;
2014
2061
  return tslib_1.__generator(this, function (_d) {
2015
2062
  switch (_d.label) {
2016
2063
  case 0:
@@ -2112,14 +2159,14 @@ var postponeReview = function (ctx, recordId, data) {
2112
2159
  return [3, 7];
2113
2160
  case 10: return [3, 13];
2114
2161
  case 11:
2115
- e_12_1 = _d.sent();
2116
- e_12 = { error: e_12_1 };
2162
+ e_13_1 = _d.sent();
2163
+ e_13 = { error: e_13_1 };
2117
2164
  return [3, 13];
2118
2165
  case 12:
2119
2166
  try {
2120
2167
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2121
2168
  }
2122
- finally { if (e_12) throw e_12.error; }
2169
+ finally { if (e_13) throw e_13.error; }
2123
2170
  return [7];
2124
2171
  case 13: return [3, 16];
2125
2172
  case 14: return [4, ctx.getObject('pepsico_review_postpone').insert({
@@ -2143,6 +2190,13 @@ var postponeReview = function (ctx, recordId, data) {
2143
2190
  _d.label = 16;
2144
2191
  case 16:
2145
2192
  console.log("[postponeReview] recordId=".concat(recordId, ", departmentType=").concat(departmentType, ", deptUserIds=").concat(deptUserIds, ", markedForNextRound=true"));
2193
+ return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
2194
+ $push: {
2195
+ postpone_marker_users: user.userId
2196
+ }
2197
+ })];
2198
+ case 17:
2199
+ _d.sent();
2146
2200
  return [2, {}];
2147
2201
  }
2148
2202
  });