pha-hermes 1.9.0 → 1.11.0

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.
@@ -575,9 +575,9 @@ var SFTimesheetClient = /*#__PURE__*/function () {
575
575
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
576
576
  while (1) switch (_context2.prev = _context2.next) {
577
577
  case 0:
578
- // First we find the correct timesheet id
578
+ // Find all timesheet Ids that belong to this WO
579
579
  url = "/services/data/" + SF_API_VERSION + "/query";
580
- query = "SELECT Id\n FROM Timesheet__c\n WHERE WorkOrder__c = '" + workorderId + "'\n LIMIT 1";
580
+ query = "SELECT Id\n FROM Timesheet__c\n WHERE WorkOrder__c = '" + workorderId + "'\n ";
581
581
  _context2.next = 4;
582
582
  return this.axiosInstance.get(url, {
583
583
  params: {
@@ -587,7 +587,9 @@ var SFTimesheetClient = /*#__PURE__*/function () {
587
587
  case 4:
588
588
  _yield$this$axiosInst = _context2.sent;
589
589
  records = _yield$this$axiosInst.data.records;
590
- return _context2.abrupt("return", records[0].Id);
590
+ return _context2.abrupt("return", records.map(function (record) {
591
+ return record.Id;
592
+ }));
591
593
  case 7:
592
594
  case "end":
593
595
  return _context2.stop();
@@ -599,54 +601,22 @@ var SFTimesheetClient = /*#__PURE__*/function () {
599
601
  }
600
602
  return getTimesheetId;
601
603
  }();
602
- _proto.getTimesheetIds = /*#__PURE__*/function () {
603
- var _getTimesheetIds = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(workorderId) {
604
- var url, query, _yield$this$axiosInst2, records;
605
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
606
- while (1) switch (_context3.prev = _context3.next) {
607
- case 0:
608
- // Find all timesheet Ids that belong to this WO
609
- url = "/services/data/" + SF_API_VERSION + "/query";
610
- query = "SELECT Id\n FROM Timesheet__c\n WHERE WorkOrder__c = '" + workorderId + "'\n ";
611
- _context3.next = 4;
612
- return this.axiosInstance.get(url, {
613
- params: {
614
- q: query
615
- }
616
- });
617
- case 4:
618
- _yield$this$axiosInst2 = _context3.sent;
619
- records = _yield$this$axiosInst2.data.records;
620
- return _context3.abrupt("return", records.map(function (record) {
621
- return record.Id;
622
- }));
623
- case 7:
624
- case "end":
625
- return _context3.stop();
626
- }
627
- }, _callee3, this);
628
- }));
629
- function getTimesheetIds(_x4) {
630
- return _getTimesheetIds.apply(this, arguments);
631
- }
632
- return getTimesheetIds;
633
- }();
634
604
  _proto.getTimesheetsForPractitioner = /*#__PURE__*/function () {
635
- var _getTimesheetsForPractitioner = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(personnelID) {
605
+ var _getTimesheetsForPractitioner = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(personnelID) {
636
606
  var url, query, data, timesheets, _iterator, _step, timesheet;
637
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
638
- while (1) switch (_context4.prev = _context4.next) {
607
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
608
+ while (1) switch (_context3.prev = _context3.next) {
639
609
  case 0:
640
610
  url = "/services/data/" + SF_API_VERSION + "/query";
641
611
  query = "SELECT FIELDS(STANDARD), WorkOrder__c\n FROM TimeSheet__c\n WHERE WorkOrder__c IN (SELECT Id\n FROM WorkOrder__c\n WHERE Personnel__c = '" + personnelID + "')";
642
- _context4.next = 4;
612
+ _context3.next = 4;
643
613
  return this.axiosInstance.get(url, {
644
614
  params: {
645
615
  q: query
646
616
  }
647
617
  });
648
618
  case 4:
649
- data = _context4.sent;
619
+ data = _context3.sent;
650
620
  timesheets = [];
651
621
  for (_iterator = _createForOfIteratorHelperLoose(data.data.records); !(_step = _iterator()).done;) {
652
622
  timesheet = _step.value;
@@ -656,169 +626,169 @@ var SFTimesheetClient = /*#__PURE__*/function () {
656
626
  updatedAt: timesheet.LastModifiedDate
657
627
  });
658
628
  }
659
- return _context4.abrupt("return", timesheets);
629
+ return _context3.abrupt("return", timesheets);
660
630
  case 8:
661
631
  case "end":
662
- return _context4.stop();
632
+ return _context3.stop();
663
633
  }
664
- }, _callee4, this);
634
+ }, _callee3, this);
665
635
  }));
666
- function getTimesheetsForPractitioner(_x5) {
636
+ function getTimesheetsForPractitioner(_x4) {
667
637
  return _getTimesheetsForPractitioner.apply(this, arguments);
668
638
  }
669
639
  return getTimesheetsForPractitioner;
670
640
  }();
671
641
  _proto.getTimesheetHoursIds = /*#__PURE__*/function () {
672
- var _getTimesheetHoursIds = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(workorderId) {
673
- var timesheetId, url, query, _yield$this$axiosInst3, records;
674
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
675
- while (1) switch (_context5.prev = _context5.next) {
642
+ var _getTimesheetHoursIds = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(workorderId) {
643
+ var timesheetIds, timesheetId, url, query, _yield$this$axiosInst2, records;
644
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
645
+ while (1) switch (_context4.prev = _context4.next) {
676
646
  case 0:
677
- _context5.next = 2;
647
+ _context4.next = 2;
678
648
  return this.getTimesheetId(workorderId);
679
649
  case 2:
680
- timesheetId = _context5.sent;
681
- // First we find the correct timesheet hours id
650
+ timesheetIds = _context4.sent;
651
+ timesheetId = timesheetIds[0]; // First we find the correct timesheet hours id
682
652
  url = "/services/data/" + SF_API_VERSION + "/query";
683
653
  query = "SELECT Id\n FROM TimesheetHour__c\n WHERE Timesheet__c = '" + timesheetId + "'";
684
- _context5.next = 7;
654
+ _context4.next = 8;
685
655
  return this.axiosInstance.get(url, {
686
656
  params: {
687
657
  q: query
688
658
  }
689
659
  });
690
- case 7:
691
- _yield$this$axiosInst3 = _context5.sent;
692
- records = _yield$this$axiosInst3.data.records;
693
- return _context5.abrupt("return", records.map(function (_ref) {
660
+ case 8:
661
+ _yield$this$axiosInst2 = _context4.sent;
662
+ records = _yield$this$axiosInst2.data.records;
663
+ return _context4.abrupt("return", records.map(function (_ref) {
694
664
  var Id = _ref.Id;
695
665
  return Id;
696
666
  }));
697
- case 10:
667
+ case 11:
698
668
  case "end":
699
- return _context5.stop();
669
+ return _context4.stop();
700
670
  }
701
- }, _callee5, this);
671
+ }, _callee4, this);
702
672
  }));
703
- function getTimesheetHoursIds(_x6) {
673
+ function getTimesheetHoursIds(_x5) {
704
674
  return _getTimesheetHoursIds.apply(this, arguments);
705
675
  }
706
676
  return getTimesheetHoursIds;
707
677
  }();
708
678
  _proto.getTimesheetHoursId = /*#__PURE__*/function () {
709
- var _getTimesheetHoursId = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(workorderId, timesheetDate) {
710
- var timesheetIds, formattedDate, allHourIds, url, _iterator2, _step2, timesheetId, query, _yield$this$axiosInst4, records, ids;
711
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
712
- while (1) switch (_context6.prev = _context6.next) {
679
+ var _getTimesheetHoursId = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(workorderId, timesheetDate) {
680
+ var timesheetIds, formattedDate, allHourIds, url, _iterator2, _step2, timesheetId, query, _yield$this$axiosInst3, records, ids;
681
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
682
+ while (1) switch (_context5.prev = _context5.next) {
713
683
  case 0:
714
- _context6.next = 2;
715
- return this.getTimesheetIds(workorderId);
684
+ _context5.next = 2;
685
+ return this.getTimesheetId(workorderId);
716
686
  case 2:
717
- timesheetIds = _context6.sent;
687
+ timesheetIds = _context5.sent;
718
688
  formattedDate = timesheetDate.toISOString().split('T')[0];
719
689
  allHourIds = [];
720
690
  url = "/services/data/" + SF_API_VERSION + "/query";
721
691
  _iterator2 = _createForOfIteratorHelperLoose(timesheetIds);
722
692
  case 7:
723
693
  if ((_step2 = _iterator2()).done) {
724
- _context6.next = 25;
694
+ _context5.next = 25;
725
695
  break;
726
696
  }
727
697
  timesheetId = _step2.value;
728
698
  query = "\n SELECT Id\n FROM TimesheetHour__c\n WHERE Timesheet__c = '" + timesheetId + "'\n AND Date__c = " + formattedDate + "\n ";
729
- _context6.prev = 10;
730
- _context6.next = 13;
699
+ _context5.prev = 10;
700
+ _context5.next = 13;
731
701
  return this.axiosInstance.get(url, {
732
702
  params: {
733
703
  q: query
734
704
  }
735
705
  });
736
706
  case 13:
737
- _yield$this$axiosInst4 = _context6.sent;
738
- records = _yield$this$axiosInst4.data.records;
707
+ _yield$this$axiosInst3 = _context5.sent;
708
+ records = _yield$this$axiosInst3.data.records;
739
709
  ids = records.map(function (record) {
740
710
  return record.Id;
741
711
  });
742
712
  allHourIds.push.apply(allHourIds, ids);
743
- _context6.next = 23;
713
+ _context5.next = 23;
744
714
  break;
745
715
  case 19:
746
- _context6.prev = 19;
747
- _context6.t0 = _context6["catch"](10);
748
- console.error("Failed to fetch", _context6.t0);
749
- return _context6.abrupt("return", []);
716
+ _context5.prev = 19;
717
+ _context5.t0 = _context5["catch"](10);
718
+ console.error("Failed to fetch", _context5.t0);
719
+ return _context5.abrupt("return", []);
750
720
  case 23:
751
- _context6.next = 7;
721
+ _context5.next = 7;
752
722
  break;
753
723
  case 25:
754
- return _context6.abrupt("return", allHourIds);
724
+ return _context5.abrupt("return", allHourIds);
755
725
  case 26:
756
726
  case "end":
757
- return _context6.stop();
727
+ return _context5.stop();
758
728
  }
759
- }, _callee6, this, [[10, 19]]);
729
+ }, _callee5, this, [[10, 19]]);
760
730
  }));
761
- function getTimesheetHoursId(_x7, _x8) {
731
+ function getTimesheetHoursId(_x6, _x7) {
762
732
  return _getTimesheetHoursId.apply(this, arguments);
763
733
  }
764
734
  return getTimesheetHoursId;
765
735
  }();
766
736
  _proto.getTimesheetHours = /*#__PURE__*/function () {
767
- var _getTimesheetHours = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(workorderId) {
737
+ var _getTimesheetHours = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(workorderId) {
768
738
  var _this = this;
769
739
  var timesheetHourIds;
770
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
771
- while (1) switch (_context8.prev = _context8.next) {
740
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
741
+ while (1) switch (_context7.prev = _context7.next) {
772
742
  case 0:
773
- _context8.next = 2;
743
+ _context7.next = 2;
774
744
  return this.getTimesheetHoursIds(workorderId);
775
745
  case 2:
776
- timesheetHourIds = _context8.sent;
777
- return _context8.abrupt("return", Promise.all(timesheetHourIds.map(/*#__PURE__*/function () {
778
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(id) {
779
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
780
- while (1) switch (_context7.prev = _context7.next) {
746
+ timesheetHourIds = _context7.sent;
747
+ return _context7.abrupt("return", Promise.all(timesheetHourIds.map(/*#__PURE__*/function () {
748
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
749
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
750
+ while (1) switch (_context6.prev = _context6.next) {
781
751
  case 0:
782
- return _context7.abrupt("return", _this.axiosInstance.get("/services/data/" + SF_API_VERSION + "/sobjects/TimeSheetHour__c/" + id).then(function (res) {
752
+ return _context6.abrupt("return", _this.axiosInstance.get("/services/data/" + SF_API_VERSION + "/sobjects/TimeSheetHour__c/" + id).then(function (res) {
783
753
  return res.data;
784
754
  }).then(toTimesheetDayEntry));
785
755
  case 1:
786
756
  case "end":
787
- return _context7.stop();
757
+ return _context6.stop();
788
758
  }
789
- }, _callee7);
759
+ }, _callee6);
790
760
  }));
791
- return function (_x10) {
761
+ return function (_x9) {
792
762
  return _ref2.apply(this, arguments);
793
763
  };
794
764
  }())));
795
765
  case 4:
796
766
  case "end":
797
- return _context8.stop();
767
+ return _context7.stop();
798
768
  }
799
- }, _callee8, this);
769
+ }, _callee7, this);
800
770
  }));
801
- function getTimesheetHours(_x9) {
771
+ function getTimesheetHours(_x8) {
802
772
  return _getTimesheetHours.apply(this, arguments);
803
773
  }
804
774
  return getTimesheetHours;
805
775
  }();
806
776
  _proto.getPayPeriods = /*#__PURE__*/function () {
807
- var _getPayPeriods = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
777
+ var _getPayPeriods = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
808
778
  var url, query, data, payPeriods, _iterator3, _step3, payPeriod;
809
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
810
- while (1) switch (_context9.prev = _context9.next) {
779
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
780
+ while (1) switch (_context8.prev = _context8.next) {
811
781
  case 0:
812
782
  url = "/services/data/" + SF_API_VERSION + "/query";
813
783
  query = "SELECT Name,\n StartDate__c,\n EndDate__c\n FROM PayPeriod__c";
814
- _context9.next = 4;
784
+ _context8.next = 4;
815
785
  return this.axiosInstance.get(url, {
816
786
  params: {
817
787
  q: query
818
788
  }
819
789
  });
820
790
  case 4:
821
- data = _context9.sent;
791
+ data = _context8.sent;
822
792
  payPeriods = [];
823
793
  for (_iterator3 = _createForOfIteratorHelperLoose(data.data.records); !(_step3 = _iterator3()).done;) {
824
794
  payPeriod = _step3.value;
@@ -828,18 +798,73 @@ var SFTimesheetClient = /*#__PURE__*/function () {
828
798
  endDate: payPeriod.EndDate__c
829
799
  });
830
800
  }
831
- return _context9.abrupt("return", payPeriods);
801
+ return _context8.abrupt("return", payPeriods);
832
802
  case 8:
833
803
  case "end":
834
- return _context9.stop();
804
+ return _context8.stop();
835
805
  }
836
- }, _callee9, this);
806
+ }, _callee8, this);
837
807
  }));
838
808
  function getPayPeriods() {
839
809
  return _getPayPeriods.apply(this, arguments);
840
810
  }
841
811
  return getPayPeriods;
842
812
  }();
813
+ _proto.uploadImageToTimesheet = /*#__PURE__*/function () {
814
+ var _uploadImageToTimesheet = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(file, filename, timesheetId) {
815
+ var form, uploadRes, versionId, _yield$this$axiosInst4, data, contentDocumentId;
816
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
817
+ while (1) switch (_context9.prev = _context9.next) {
818
+ case 0:
819
+ _context9.prev = 0;
820
+ form = new FormData();
821
+ form.append('Title', filename);
822
+ form.append('PathOnClient', filename);
823
+ form.append('VersionData', file, {
824
+ filename: filename
825
+ });
826
+ _context9.next = 7;
827
+ return this.axiosInstance.post("/services/data/" + SF_API_VERSION + "/sobjects/ContentVersion", form, {
828
+ headers: form.getHeaders()
829
+ });
830
+ case 7:
831
+ uploadRes = _context9.sent;
832
+ versionId = uploadRes.data.id; //get ContentDocumentId
833
+ _context9.next = 11;
834
+ return this.axiosInstance.get("/services/data/" + SF_API_VERSION + "/query", {
835
+ params: {
836
+ q: "SELECT ContentDocumentId FROM ContentVersion WHERE Id = '" + versionId + "'"
837
+ }
838
+ });
839
+ case 11:
840
+ _yield$this$axiosInst4 = _context9.sent;
841
+ data = _yield$this$axiosInst4.data;
842
+ contentDocumentId = data.records[0].ContentDocumentId;
843
+ _context9.next = 16;
844
+ return this.axiosInstance.post("/services/data/" + SF_API_VERSION + "/sobjects/ContentDocumentLink", {
845
+ ContentDocumentId: contentDocumentId,
846
+ LinkedEntityId: timesheetId,
847
+ ShareType: 'V',
848
+ Visibility: 'AllUsers'
849
+ });
850
+ case 16:
851
+ _context9.next = 21;
852
+ break;
853
+ case 18:
854
+ _context9.prev = 18;
855
+ _context9.t0 = _context9["catch"](0);
856
+ console.error('Error uploading and linking image:', _context9.t0.message);
857
+ case 21:
858
+ case "end":
859
+ return _context9.stop();
860
+ }
861
+ }, _callee9, this, [[0, 18]]);
862
+ }));
863
+ function uploadImageToTimesheet(_x10, _x11, _x12) {
864
+ return _uploadImageToTimesheet.apply(this, arguments);
865
+ }
866
+ return uploadImageToTimesheet;
867
+ }();
843
868
  return SFTimesheetClient;
844
869
  }();
845
870
  function toTimesheetDayEntry(raw) {