@steedos-labs/content-compliance-bev 0.1.21 → 0.1.23

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.
@@ -13,3 +13,4 @@ export * from './dashboard_sync_data';
13
13
  export * from './sendToContentHub';
14
14
  export * from './spotCheckMaterial';
15
15
  export * from './initPersonPendingUser';
16
+ export * from './initDisplayHandler';
@@ -16,4 +16,5 @@ tslib_1.__exportStar(require("./dashboard_sync_data"), exports);
16
16
  tslib_1.__exportStar(require("./sendToContentHub"), exports);
17
17
  tslib_1.__exportStar(require("./spotCheckMaterial"), exports);
18
18
  tslib_1.__exportStar(require("./initPersonPendingUser"), exports);
19
+ tslib_1.__exportStar(require("./initDisplayHandler"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":";;;AAOA,mDAAyB;AAEzB,sDAA4B;AAE5B,6DAAmC;AAEnC,2DAAiC;AAEjC,8DAAoC;AAEpC,+DAAqC;AAErC,uDAA6B;AAE7B,iDAAuB;AAEvB,kEAAwC;AAExC,qDAA2B;AAE3B,uDAA6B;AAE7B,gEAAsC;AAEtC,6DAAmC;AAEnC,8DAAoC;AAEpC,kEAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":";;;AAOA,mDAAyB;AAEzB,sDAA4B;AAE5B,6DAAmC;AAEnC,2DAAiC;AAEjC,8DAAoC;AAEpC,+DAAqC;AAErC,uDAA6B;AAE7B,iDAAuB;AAEvB,kEAAwC;AAExC,qDAA2B;AAE3B,uDAA6B;AAE7B,gEAAsC;AAEtC,6DAAmC;AAEnC,8DAAoC;AAEpC,kEAAwC;AAExC,+DAAqC"}
@@ -0,0 +1,7 @@
1
+ export declare const initDisplayHandler: {
2
+ rest: {
3
+ method: string;
4
+ fullPath: string;
5
+ };
6
+ handler(ctx: any): Promise<any>;
7
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initDisplayHandler = void 0;
4
+ var tslib_1 = require("tslib");
5
+ exports.initDisplayHandler = {
6
+ rest: {
7
+ method: 'GET',
8
+ fullPath: '/api/pepsico-content/approve/init-display-handler'
9
+ },
10
+ handler: function (ctx) {
11
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
12
+ var logger;
13
+ return tslib_1.__generator(this, function (_a) {
14
+ switch (_a.label) {
15
+ case 0:
16
+ ctx.getObject = this.getObject;
17
+ return [4, this.getLogger()];
18
+ case 1:
19
+ logger = _a.sent();
20
+ ctx.logger = logger;
21
+ return [4, this.initDisplayHandler(ctx)];
22
+ case 2: return [2, _a.sent()];
23
+ }
24
+ });
25
+ });
26
+ }
27
+ };
28
+ //# sourceMappingURL=initDisplayHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initDisplayHandler.js","sourceRoot":"","sources":["../../src/actions/initDisplayHandler.ts"],"names":[],"mappings":";;;;AAAa,QAAA,kBAAkB,GAAG;IAC9B,IAAI,EAAE;QACF,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,mDAAmD;KAChE;IACK,OAAO,YAAC,GAAG;;;;;;wBACb,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;wBAChB,WAAM,IAAI,CAAC,SAAS,EAAE,EAAA;;wBAA/B,MAAM,GAAG,SAAsB;wBACrC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;wBACb,WAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAA;4BAAzC,WAAO,SAAkC,EAAC;;;;KAC7C;CACJ,CAAA"}
@@ -27,3 +27,9 @@ export declare const initPersonPendingUser: (ctx: any) => Promise<{
27
27
  updated: number;
28
28
  skipped: number;
29
29
  }>;
30
+ export declare const initDisplayHandler: (ctx: any) => Promise<{
31
+ spaceId: any;
32
+ scanned: number;
33
+ updated: number;
34
+ skipped: number;
35
+ }>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initPersonPendingUser = exports.submitContent = exports.submitKidsContent = exports.rejectContent = exports.approvalContent = exports.postponeDeployment = exports.confirmDeployment = exports.terminate = exports.getApproverStepRule = exports.getDefApproverStepRule = void 0;
3
+ exports.initDisplayHandler = exports.initPersonPendingUser = exports.submitContent = exports.submitKidsContent = exports.rejectContent = exports.approvalContent = exports.postponeDeployment = exports.confirmDeployment = exports.terminate = exports.getApproverStepRule = exports.getDefApproverStepRule = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var consts_1 = require("./consts");
6
6
  var amis_formula_1 = require("amis-formula");
@@ -402,7 +402,7 @@ var getHandlerFieldByApproveField = function (approveField) {
402
402
  return mapping[approveField] || null;
403
403
  };
404
404
  var updateApproveFieldStatus = function (ctx, recordId, approveField, approveFieldValue) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
405
- var userId, set, approvalNew, approvals, handlerField, handlerUserIds_1, filteredApprovals, currentTypeMapping, currentType, remainingProcessFilters, remainingProcess, pendingUsers;
405
+ var userId, set, approvalNew_1, approvals, handlerField, handlerUserIds, allHandlerMappings_1, usersToRemove_1, filteredApprovals, currentTypeMapping, currentType, remainingProcessFilters, remainingProcess, pendingUsers;
406
406
  var _a;
407
407
  return tslib_1.__generator(this, function (_b) {
408
408
  switch (_b.label) {
@@ -415,11 +415,41 @@ var updateApproveFieldStatus = function (ctx, recordId, approveField, approveFie
415
415
  if (!userId) return [3, 3];
416
416
  return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
417
417
  case 1:
418
- approvalNew = _b.sent();
419
- approvals = (Array.isArray(approvalNew.person_pending_approve) ? approvalNew.person_pending_approve : []);
418
+ approvalNew_1 = _b.sent();
419
+ approvals = (Array.isArray(approvalNew_1.person_pending_approve) ? approvalNew_1.person_pending_approve : []);
420
420
  handlerField = getHandlerFieldByApproveField(approveField);
421
- handlerUserIds_1 = handlerField ? (approvalNew[handlerField] || []) : [userId];
422
- filteredApprovals = approvals.filter(function (id) { return !handlerUserIds_1.includes(id); });
421
+ handlerUserIds = handlerField ? (approvalNew_1[handlerField] || []) : [userId];
422
+ allHandlerMappings_1 = {
423
+ 'ca_approval_status': 'handler_ca',
424
+ 'ns_approval_status': 'handler_ns',
425
+ 'legal_approval_status': 'handler_legal',
426
+ 'sra_approval_status': 'handler_sra',
427
+ 'approval_status': 'handler_guding',
428
+ 'kids_approval_status': 'handler_kids',
429
+ };
430
+ usersToRemove_1 = handlerUserIds.filter(function (uid) {
431
+ var e_3, _a;
432
+ try {
433
+ for (var _b = tslib_1.__values(Object.entries(allHandlerMappings_1)), _c = _b.next(); !_c.done; _c = _b.next()) {
434
+ var _d = tslib_1.__read(_c.value, 2), statusField = _d[0], hField = _d[1];
435
+ if (statusField === approveField)
436
+ continue;
437
+ var handlers = approvalNew_1[hField] || [];
438
+ if (_.includes(handlers, uid) && !hasReviewed(approvalNew_1[statusField])) {
439
+ return false;
440
+ }
441
+ }
442
+ }
443
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
444
+ finally {
445
+ try {
446
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
447
+ }
448
+ finally { if (e_3) throw e_3.error; }
449
+ }
450
+ return true;
451
+ });
452
+ filteredApprovals = approvals.filter(function (id) { return !usersToRemove_1.includes(id); });
423
453
  set.person_pending_approve = filteredApprovals;
424
454
  currentTypeMapping = {
425
455
  'ca_approval_status': 'CA',
@@ -433,7 +463,7 @@ var updateApproveFieldStatus = function (ctx, recordId, approveField, approveFie
433
463
  remainingProcessFilters = [
434
464
  ['owner', '=', userId],
435
465
  ['pepsico_material_approval', '=', recordId],
436
- ['space', '=', approvalNew.space],
466
+ ['space', '=', approvalNew_1.space],
437
467
  ['approved', '=', 'progess']
438
468
  ];
439
469
  if (currentType) {
@@ -445,11 +475,11 @@ var updateApproveFieldStatus = function (ctx, recordId, approveField, approveFie
445
475
  case 2:
446
476
  remainingProcess = _b.sent();
447
477
  if (remainingProcess === 0) {
448
- pendingUsers = (Array.isArray(approvalNew.person_pending_user) ? approvalNew.person_pending_user : []);
478
+ pendingUsers = (Array.isArray(approvalNew_1.person_pending_user) ? approvalNew_1.person_pending_user : []);
449
479
  set.person_pending_user = pendingUsers.filter(function (id) { return id !== userId; });
450
480
  }
451
481
  set.$push = {
452
- person_approved: { $each: handlerUserIds_1 },
482
+ person_approved: { $each: handlerUserIds },
453
483
  person_done: userId
454
484
  };
455
485
  _b.label = 3;
@@ -466,8 +496,8 @@ var updateApproveFieldStatus = function (ctx, recordId, approveField, approveFie
466
496
  var changeApprovalProcess = function (ctx, materialApproval, _a) {
467
497
  var nextStep = _a.nextStep, nextApprovers = _a.nextApprovers, description = _a.description;
468
498
  return tslib_1.__awaiter(void 0, void 0, void 0, function () {
469
- var user, count, now, sUsers, _b, nextApprovers_1, nextApprovers_1_1, nextApprover, _c, _d, userId, spaceUsers, e_3_1, e_4_1;
470
- var e_4, _e, e_3, _f, _g;
499
+ var user, count, now, sUsers, _b, nextApprovers_1, nextApprovers_1_1, nextApprover, _c, _d, userId, spaceUsers, e_4_1, handlerKey, displayKey, existingDisplay, unionDisplay, e_5_1;
500
+ var e_5, _e, e_4, _f, _g;
471
501
  return tslib_1.__generator(this, function (_h) {
472
502
  switch (_h.label) {
473
503
  case 0:
@@ -524,7 +554,7 @@ var changeApprovalProcess = function (ctx, materialApproval, _a) {
524
554
  _h.label = 6;
525
555
  case 6:
526
556
  _h.trys.push([6, 12, 13, 14]);
527
- _c = (e_3 = void 0, tslib_1.__values(nextApprover.userIds)), _d = _c.next();
557
+ _c = (e_4 = void 0, tslib_1.__values(nextApprover.userIds)), _d = _c.next();
528
558
  _h.label = 7;
529
559
  case 7:
530
560
  if (!!_d.done) return [3, 11];
@@ -554,19 +584,24 @@ var changeApprovalProcess = function (ctx, materialApproval, _a) {
554
584
  return [3, 7];
555
585
  case 11: return [3, 14];
556
586
  case 12:
557
- e_3_1 = _h.sent();
558
- e_3 = { error: e_3_1 };
587
+ e_4_1 = _h.sent();
588
+ e_4 = { error: e_4_1 };
559
589
  return [3, 14];
560
590
  case 13:
561
591
  try {
562
592
  if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
563
593
  }
564
- finally { if (e_3) throw e_3.error; }
594
+ finally { if (e_4) throw e_4.error; }
565
595
  return [7];
566
596
  case 14:
567
597
  if (!nextApprover.type) return [3, 16];
598
+ handlerKey = "handler_".concat((0, lodash_1.toLower)(nextApprover.type));
599
+ displayKey = "display_handler_".concat((0, lodash_1.toLower)(nextApprover.type));
600
+ existingDisplay = materialApproval[displayKey] || [];
601
+ unionDisplay = _.union(existingDisplay, nextApprover.userIds);
568
602
  return [4, ctx.getObject('pepsico_material_approval').directUpdate(materialApproval._id, (_g = {},
569
- _g["handler_".concat((0, lodash_1.toLower)(nextApprover.type))] = nextApprover.userIds,
603
+ _g[handlerKey] = nextApprover.userIds,
604
+ _g[displayKey] = unionDisplay,
570
605
  _g))];
571
606
  case 15:
572
607
  _h.sent();
@@ -576,14 +611,14 @@ var changeApprovalProcess = function (ctx, materialApproval, _a) {
576
611
  return [3, 5];
577
612
  case 17: return [3, 20];
578
613
  case 18:
579
- e_4_1 = _h.sent();
580
- e_4 = { error: e_4_1 };
614
+ e_5_1 = _h.sent();
615
+ e_5 = { error: e_5_1 };
581
616
  return [3, 20];
582
617
  case 19:
583
618
  try {
584
619
  if (nextApprovers_1_1 && !nextApprovers_1_1.done && (_e = nextApprovers_1.return)) _e.call(nextApprovers_1);
585
620
  }
586
- finally { if (e_4) throw e_4.error; }
621
+ finally { if (e_5) throw e_5.error; }
587
622
  return [7];
588
623
  case 20: return [3, 24];
589
624
  case 21: return [4, ctx.getObject('pepsico_approval_process').insert({
@@ -637,8 +672,8 @@ var setPersonView = function (ctx, materialApproval) { return tslib_1.__awaiter(
637
672
  });
638
673
  }); };
639
674
  var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
640
- var actionLabel, user, record, nextStep, skipApprover, nextApprovers, _nextApprovers, nextApprovers_2, nextApprovers_2_1, reviewer, fieldName, status, filteredUserIds, filteredClientUserIds, i, userId, lastProcess, e_5_1, nextApproversUserIds_1, nextApproversClientUserIds_1, setDoc, nextApprovers_3, nextApprovers_3_1, nextApprover, e_6_1, setDoc_1, isConclusionApproved, error_1;
641
- var e_5, _a, _b, _c, e_6, _d;
675
+ var actionLabel, user, record, nextStep, skipApprover, nextApprovers, _nextApprovers, nextApprovers_2, nextApprovers_2_1, reviewer, fieldName, status, filteredUserIds, filteredClientUserIds, i, userId, lastProcess, e_6_1, nextApproversUserIds_1, nextApproversClientUserIds_1, setDoc, nextApprovers_3, nextApprovers_3_1, nextApprover, e_7_1, setDoc_1, isConclusionApproved, error_1;
676
+ var e_6, _a, _b, _c, e_7, _d;
642
677
  return tslib_1.__generator(this, function (_e) {
643
678
  switch (_e.label) {
644
679
  case 0:
@@ -777,14 +812,14 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
777
812
  return [3, 14];
778
813
  case 24: return [3, 27];
779
814
  case 25:
780
- e_5_1 = _e.sent();
781
- e_5 = { error: e_5_1 };
815
+ e_6_1 = _e.sent();
816
+ e_6 = { error: e_6_1 };
782
817
  return [3, 27];
783
818
  case 26:
784
819
  try {
785
820
  if (nextApprovers_2_1 && !nextApprovers_2_1.done && (_a = nextApprovers_2.return)) _a.call(nextApprovers_2);
786
821
  }
787
- finally { if (e_5) throw e_5.error; }
822
+ finally { if (e_6) throw e_6.error; }
788
823
  return [7];
789
824
  case 27:
790
825
  if (!(_nextApprovers.length > 0)) return [3, 28];
@@ -981,14 +1016,14 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
981
1016
  return [3, 37];
982
1017
  case 62: return [3, 65];
983
1018
  case 63:
984
- e_6_1 = _e.sent();
985
- e_6 = { error: e_6_1 };
1019
+ e_7_1 = _e.sent();
1020
+ e_7 = { error: e_7_1 };
986
1021
  return [3, 65];
987
1022
  case 64:
988
1023
  try {
989
1024
  if (nextApprovers_3_1 && !nextApprovers_3_1.done && (_d = nextApprovers_3.return)) _d.call(nextApprovers_3);
990
1025
  }
991
- finally { if (e_6) throw e_6.error; }
1026
+ finally { if (e_7) throw e_7.error; }
992
1027
  return [7];
993
1028
  case 65:
994
1029
  if (!(nextStep === consts_1.Step.departmental_review || nextStep === consts_1.Step.personnel_review)) return [3, 67];
@@ -1066,8 +1101,8 @@ var advanceApproval = function (ctx, recordId, currentStepApprovalStatus) { retu
1066
1101
  });
1067
1102
  }); };
1068
1103
  var terminate = function (ctx, recordId, description) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
1069
- var user, record, records, records_1, records_1_1, process_2, e_7_1;
1070
- var e_7, _a;
1104
+ var user, record, records, records_1, records_1_1, process_2, e_8_1;
1105
+ var e_8, _a;
1071
1106
  return tslib_1.__generator(this, function (_b) {
1072
1107
  switch (_b.label) {
1073
1108
  case 0:
@@ -1116,14 +1151,14 @@ var terminate = function (ctx, recordId, description) { return tslib_1.__awaiter
1116
1151
  return [3, 5];
1117
1152
  case 8: return [3, 11];
1118
1153
  case 9:
1119
- e_7_1 = _b.sent();
1120
- e_7 = { error: e_7_1 };
1154
+ e_8_1 = _b.sent();
1155
+ e_8 = { error: e_8_1 };
1121
1156
  return [3, 11];
1122
1157
  case 10:
1123
1158
  try {
1124
1159
  if (records_1_1 && !records_1_1.done && (_a = records_1.return)) _a.call(records_1);
1125
1160
  }
1126
- finally { if (e_7) throw e_7.error; }
1161
+ finally { if (e_8) throw e_8.error; }
1127
1162
  return [7];
1128
1163
  case 11: return [4, ctx.getObject('pepsico_material_approval').update(recordId, {
1129
1164
  current_step: consts_1.Step.conclusion,
@@ -1444,8 +1479,8 @@ var submitKidsContent = function (ctx, recordId, currentStepApprovalStatus) {
1444
1479
  exports.submitKidsContent = submitKidsContent;
1445
1480
  var submitContent = function (ctx, recordId, currentStepApprovalStatus, skip) {
1446
1481
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1447
- var approvalNew, user, allow, aProcess, aProcess_1, aProcess_1_1, item, e_8_1, pepsicoMaterial, spaceUsers, owner, approvalType, allTrue1, allTrue, spaceUsers, owner, materials, pendingUploadMaterials;
1448
- var e_8, _a;
1482
+ var approvalNew, user, allow, aProcess, aProcess_1, aProcess_1_1, item, e_9_1, pepsicoMaterial, spaceUsers, owner, approvalType, allTrue1, allTrue, spaceUsers, owner, materials, pendingUploadMaterials;
1483
+ var e_9, _a;
1449
1484
  return tslib_1.__generator(this, function (_b) {
1450
1485
  switch (_b.label) {
1451
1486
  case 0: return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
@@ -1503,14 +1538,14 @@ var submitContent = function (ctx, recordId, currentStepApprovalStatus, skip) {
1503
1538
  return [3, 4];
1504
1539
  case 7: return [3, 10];
1505
1540
  case 8:
1506
- e_8_1 = _b.sent();
1507
- e_8 = { error: e_8_1 };
1541
+ e_9_1 = _b.sent();
1542
+ e_9 = { error: e_9_1 };
1508
1543
  return [3, 10];
1509
1544
  case 9:
1510
1545
  try {
1511
1546
  if (aProcess_1_1 && !aProcess_1_1.done && (_a = aProcess_1.return)) _a.call(aProcess_1);
1512
1547
  }
1513
- finally { if (e_8) throw e_8.error; }
1548
+ finally { if (e_9) throw e_9.error; }
1514
1549
  return [7];
1515
1550
  case 10:
1516
1551
  if (allow != true && approvalNew.current_step != consts_1.Step.draft && !(0, lodash_1.includes)(approvalNew.person_pending_approve, user.userId)) {
@@ -1650,8 +1685,8 @@ exports.submitContent = submitContent;
1650
1685
  var initPersonPendingUser = function (ctx) {
1651
1686
  var _a;
1652
1687
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1653
- var user, spaceId, approvals, updated, skipped, approvals_1, approvals_1_1, item, pendingApprove, e_9_1;
1654
- var e_9, _b;
1688
+ var user, spaceId, approvals, updated, skipped, approvals_1, approvals_1_1, item, pendingApprove, e_10_1;
1689
+ var e_10, _b;
1655
1690
  return tslib_1.__generator(this, function (_c) {
1656
1691
  switch (_c.label) {
1657
1692
  case 0:
@@ -1698,14 +1733,14 @@ var initPersonPendingUser = function (ctx) {
1698
1733
  return [3, 3];
1699
1734
  case 6: return [3, 9];
1700
1735
  case 7:
1701
- e_9_1 = _c.sent();
1702
- e_9 = { error: e_9_1 };
1736
+ e_10_1 = _c.sent();
1737
+ e_10 = { error: e_10_1 };
1703
1738
  return [3, 9];
1704
1739
  case 8:
1705
1740
  try {
1706
1741
  if (approvals_1_1 && !approvals_1_1.done && (_b = approvals_1.return)) _b.call(approvals_1);
1707
1742
  }
1708
- finally { if (e_9) throw e_9.error; }
1743
+ finally { if (e_10) throw e_10.error; }
1709
1744
  return [7];
1710
1745
  case 9: return [2, {
1711
1746
  spaceId: spaceId,
@@ -1724,4 +1759,93 @@ var hasReviewed = function (approvalStatus) {
1724
1759
  }
1725
1760
  return false;
1726
1761
  };
1762
+ var initDisplayHandler = function (ctx) {
1763
+ var _a;
1764
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1765
+ var user, spaceId, handlerFields, fields, approvals, updated, skipped, approvals_2, approvals_2_1, item, updateData, needsUpdate, handlerFields_1, handlerFields_1_1, handlerField, displayField, handlerValue, displayValue, e_11_1;
1766
+ var e_11, _b, e_12, _c;
1767
+ return tslib_1.__generator(this, function (_d) {
1768
+ switch (_d.label) {
1769
+ case 0:
1770
+ user = ctx.meta.user;
1771
+ if (!(user === null || user === void 0 ? void 0 : user.is_space_admin)) {
1772
+ throw new Error('只有系统管理员可以执行此操作.');
1773
+ }
1774
+ spaceId = (user === null || user === void 0 ? void 0 : user.spaceId) || ((_a = user === null || user === void 0 ? void 0 : user.space) === null || _a === void 0 ? void 0 : _a._id);
1775
+ if (!spaceId) {
1776
+ throw new Error('无法识别当前空间.');
1777
+ }
1778
+ handlerFields = ['handler_ca', 'handler_ns', 'handler_legal', 'handler_sra', 'handler_kids', 'handler_guding'];
1779
+ fields = tslib_1.__spreadArray(tslib_1.__spreadArray(['_id'], tslib_1.__read(handlerFields), false), tslib_1.__read(handlerFields.map(function (f) { return f.replace('handler_', 'display_handler_'); })), false);
1780
+ return [4, ctx.getObject('pepsico_material_approval').find({
1781
+ filters: [['space', '=', spaceId]],
1782
+ fields: fields
1783
+ })];
1784
+ case 1:
1785
+ approvals = _d.sent();
1786
+ updated = 0;
1787
+ skipped = 0;
1788
+ _d.label = 2;
1789
+ case 2:
1790
+ _d.trys.push([2, 8, 9, 10]);
1791
+ approvals_2 = tslib_1.__values(approvals), approvals_2_1 = approvals_2.next();
1792
+ _d.label = 3;
1793
+ case 3:
1794
+ if (!!approvals_2_1.done) return [3, 7];
1795
+ item = approvals_2_1.value;
1796
+ updateData = {};
1797
+ needsUpdate = false;
1798
+ try {
1799
+ for (handlerFields_1 = (e_12 = void 0, tslib_1.__values(handlerFields)), handlerFields_1_1 = handlerFields_1.next(); !handlerFields_1_1.done; handlerFields_1_1 = handlerFields_1.next()) {
1800
+ handlerField = handlerFields_1_1.value;
1801
+ displayField = handlerField.replace('handler_', 'display_handler_');
1802
+ handlerValue = item[handlerField];
1803
+ displayValue = item[displayField];
1804
+ if (!_.isEmpty(handlerValue) && _.isEmpty(displayValue)) {
1805
+ updateData[displayField] = handlerValue;
1806
+ needsUpdate = true;
1807
+ }
1808
+ }
1809
+ }
1810
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
1811
+ finally {
1812
+ try {
1813
+ if (handlerFields_1_1 && !handlerFields_1_1.done && (_c = handlerFields_1.return)) _c.call(handlerFields_1);
1814
+ }
1815
+ finally { if (e_12) throw e_12.error; }
1816
+ }
1817
+ if (!needsUpdate) return [3, 5];
1818
+ return [4, ctx.getObject('pepsico_material_approval').directUpdate(item._id, updateData)];
1819
+ case 4:
1820
+ _d.sent();
1821
+ updated += 1;
1822
+ return [3, 6];
1823
+ case 5:
1824
+ skipped += 1;
1825
+ _d.label = 6;
1826
+ case 6:
1827
+ approvals_2_1 = approvals_2.next();
1828
+ return [3, 3];
1829
+ case 7: return [3, 10];
1830
+ case 8:
1831
+ e_11_1 = _d.sent();
1832
+ e_11 = { error: e_11_1 };
1833
+ return [3, 10];
1834
+ case 9:
1835
+ try {
1836
+ if (approvals_2_1 && !approvals_2_1.done && (_b = approvals_2.return)) _b.call(approvals_2);
1837
+ }
1838
+ finally { if (e_11) throw e_11.error; }
1839
+ return [7];
1840
+ case 10: return [2, {
1841
+ spaceId: spaceId,
1842
+ scanned: approvals.length,
1843
+ updated: updated,
1844
+ skipped: skipped
1845
+ }];
1846
+ }
1847
+ });
1848
+ });
1849
+ };
1850
+ exports.initDisplayHandler = initDisplayHandler;
1727
1851
  //# sourceMappingURL=approval_engine.js.map