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