pha-hermes 1.12.0 → 1.13.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,35 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  import { AxiosInstance } from 'axios';
3
3
  import { TimesheetDayEntry } from '../../models';
4
- interface SFTimesheetHourField {
5
- Id: string;
6
- Date__c: Date;
7
- Callback__c: number;
8
- HoursEBAdjusted__c: number;
9
- Misc__c: number;
10
- OT1__c: number;
11
- OT2__c: number;
12
- OnCall__c: number;
13
- Misc1__c: number;
14
- Misc_1_Hours__c: number;
15
- Misc_2_Hours__c: number;
16
- Misc_3_Hours__c: number;
17
- Misc_4_Hours__c: number;
18
- Stat1__c: number;
19
- Stat2__c: number;
20
- In_Charge__c: number;
21
- Shift_Travel_Stipend__c: number;
22
- LastModifiedDate: Date;
23
- }
24
- declare type SFTimesheetHourFieldKeys = (keyof SFTimesheetHourField)[];
25
4
  export declare class SFTimesheetClient {
26
5
  private axiosInstance;
27
6
  constructor(axiosInstance: AxiosInstance);
28
7
  updateTimesheetHour(timesheetHourId: string, timesheet: TimesheetDayEntry): Promise<void>;
29
- getTimesheetIds(workorderId: string, periodStartDate?: Date, periodEndDate?: Date): Promise<string[]>;
8
+ getTimesheetId(workorderId: string): Promise<string>;
30
9
  getTimesheetsForPractitioner(personnelID: string): Promise<any[]>;
31
- getTimesheetHours(workorderId: string, fields?: SFTimesheetHourFieldKeys[], periodStartDate?: Date, periodEndDate?: Date): Promise<TimesheetDayEntry[]>;
10
+ getTimesheetHoursIds(workorderId: string): Promise<string[]>;
11
+ getTimesheetHoursId(workorderId: string, timesheetDate: Date): Promise<string[]>;
12
+ getTimesheetHours(workorderId: string): Promise<TimesheetDayEntry[]>;
32
13
  getPayPeriods(): Promise<any>;
33
14
  uploadImageToTimesheet(file: Buffer, filename: string, timesheetId: string): Promise<void>;
34
15
  }
35
- export {};
@@ -575,44 +575,37 @@ var SFTimesheetClient = /*#__PURE__*/function () {
575
575
  }
576
576
  return updateTimesheetHour;
577
577
  }();
578
- _proto.getTimesheetIds = /*#__PURE__*/function () {
579
- var _getTimesheetIds = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(workorderId, periodStartDate, periodEndDate) {
578
+ _proto.getTimesheetId = /*#__PURE__*/function () {
579
+ var _getTimesheetId = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(workorderId) {
580
580
  var url, query, _yield$this$axiosInst, records;
581
581
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
582
582
  while (1) switch (_context2.prev = _context2.next) {
583
583
  case 0:
584
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 + "'";
587
- try {
588
- if (periodStartDate && periodEndDate) {
589
- query += "\n AND PayPeriodStartDate__c <= " + new Date(periodStartDate).toISOString().substring(0, 10) + "\n AND PayPeriodEndDate__c >= " + new Date(periodEndDate).toISOString().substring(0, 10) + "\n ";
590
- }
591
- } catch (error) {
592
- console.error('Invalid period dates', error);
593
- }
594
- _context2.next = 5;
586
+ query = "SELECT Id\n FROM Timesheet__c\n WHERE WorkOrder__c = '" + workorderId + "'\n ";
587
+ _context2.next = 4;
595
588
  return this.axiosInstance.get(url, {
596
589
  params: {
597
590
  q: query
598
591
  }
599
592
  });
600
- case 5:
593
+ case 4:
601
594
  _yield$this$axiosInst = _context2.sent;
602
595
  records = _yield$this$axiosInst.data.records;
603
596
  return _context2.abrupt("return", records.map(function (record) {
604
597
  return record.Id;
605
598
  }));
606
- case 8:
599
+ case 7:
607
600
  case "end":
608
601
  return _context2.stop();
609
602
  }
610
603
  }, _callee2, this);
611
604
  }));
612
- function getTimesheetIds(_x3, _x4, _x5) {
613
- return _getTimesheetIds.apply(this, arguments);
605
+ function getTimesheetId(_x3) {
606
+ return _getTimesheetId.apply(this, arguments);
614
607
  }
615
- return getTimesheetIds;
608
+ return getTimesheetId;
616
609
  }();
617
610
  _proto.getTimesheetsForPractitioner = /*#__PURE__*/function () {
618
611
  var _getTimesheetsForPractitioner = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(personnelID) {
@@ -646,83 +639,162 @@ var SFTimesheetClient = /*#__PURE__*/function () {
646
639
  }
647
640
  }, _callee3, this);
648
641
  }));
649
- function getTimesheetsForPractitioner(_x6) {
642
+ function getTimesheetsForPractitioner(_x4) {
650
643
  return _getTimesheetsForPractitioner.apply(this, arguments);
651
644
  }
652
645
  return getTimesheetsForPractitioner;
653
646
  }();
654
- _proto.getTimesheetHours = /*#__PURE__*/function () {
655
- var _getTimesheetHours = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(workorderId, fields, periodStartDate, periodEndDate) {
656
- var timesheetIds, allHours, url, _iterator2, _step2, timesheetId, query, _yield$this$axiosInst2, records;
647
+ _proto.getTimesheetHoursIds = /*#__PURE__*/function () {
648
+ var _getTimesheetHoursIds = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(workorderId) {
649
+ var timesheetIds, timesheetId, url, query, _yield$this$axiosInst2, records;
657
650
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
658
651
  while (1) switch (_context4.prev = _context4.next) {
659
652
  case 0:
660
653
  _context4.next = 2;
661
- return this.getTimesheetIds(workorderId, periodStartDate, periodEndDate);
654
+ return this.getTimesheetId(workorderId);
662
655
  case 2:
663
656
  timesheetIds = _context4.sent;
664
- allHours = [];
657
+ timesheetId = timesheetIds[0]; // First we find the correct timesheet hours id
658
+ url = "/services/data/" + SF_API_VERSION + "/query";
659
+ query = "SELECT Id\n FROM TimesheetHour__c\n WHERE Timesheet__c = '" + timesheetId + "'";
660
+ _context4.next = 8;
661
+ return this.axiosInstance.get(url, {
662
+ params: {
663
+ q: query
664
+ }
665
+ });
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) {
670
+ var Id = _ref.Id;
671
+ return Id;
672
+ }));
673
+ case 11:
674
+ case "end":
675
+ return _context4.stop();
676
+ }
677
+ }, _callee4, this);
678
+ }));
679
+ function getTimesheetHoursIds(_x5) {
680
+ return _getTimesheetHoursIds.apply(this, arguments);
681
+ }
682
+ return getTimesheetHoursIds;
683
+ }();
684
+ _proto.getTimesheetHoursId = /*#__PURE__*/function () {
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) {
689
+ case 0:
690
+ _context5.next = 2;
691
+ return this.getTimesheetId(workorderId);
692
+ case 2:
693
+ timesheetIds = _context5.sent;
694
+ formattedDate = timesheetDate.toISOString().split('T')[0];
695
+ allHourIds = [];
665
696
  url = "/services/data/" + SF_API_VERSION + "/query";
666
697
  _iterator2 = _createForOfIteratorHelperLoose(timesheetIds);
667
- case 6:
698
+ case 7:
668
699
  if ((_step2 = _iterator2()).done) {
669
- _context4.next = 23;
700
+ _context5.next = 25;
670
701
  break;
671
702
  }
672
703
  timesheetId = _step2.value;
673
- query = "\n SELECT " + ((fields == null ? void 0 : fields.join(',')) || 'FIELDS(STANDARD)') + "\n FROM TimesheetHour__c\n WHERE Timesheet__c = '" + timesheetId + "'";
674
- _context4.prev = 9;
675
- if (fields != null && fields.length) {
676
- query += "\n AND Date__c >= " + new Date(periodStartDate).toISOString().substring(0, 10) + "\n AND Date__c <= " + new Date(periodEndDate).toISOString().substring(0, 10);
677
- }
678
- _context4.next = 13;
704
+ query = "\n SELECT Id\n FROM TimesheetHour__c\n WHERE Timesheet__c = '" + timesheetId + "'\n AND Date__c = " + formattedDate + "\n ";
705
+ _context5.prev = 10;
706
+ _context5.next = 13;
679
707
  return this.axiosInstance.get(url, {
680
708
  params: {
681
709
  q: query
682
710
  }
683
711
  });
684
712
  case 13:
685
- _yield$this$axiosInst2 = _context4.sent;
686
- records = _yield$this$axiosInst2.data.records;
687
- allHours.push.apply(allHours, records);
688
- _context4.next = 21;
689
- break;
690
- case 18:
691
- _context4.prev = 18;
692
- _context4.t0 = _context4["catch"](9);
693
- console.error("Failed to fetch", _context4.t0);
694
- case 21:
695
- _context4.next = 6;
713
+ _yield$this$axiosInst3 = _context5.sent;
714
+ records = _yield$this$axiosInst3.data.records;
715
+ ids = records.map(function (record) {
716
+ return record.Id;
717
+ });
718
+ allHourIds.push.apply(allHourIds, ids);
719
+ _context5.next = 23;
696
720
  break;
721
+ case 19:
722
+ _context5.prev = 19;
723
+ _context5.t0 = _context5["catch"](10);
724
+ console.error("Failed to fetch", _context5.t0);
725
+ return _context5.abrupt("return", []);
697
726
  case 23:
698
- return _context4.abrupt("return", allHours.map(toTimesheetDayEntry));
699
- case 24:
727
+ _context5.next = 7;
728
+ break;
729
+ case 25:
730
+ return _context5.abrupt("return", allHourIds);
731
+ case 26:
700
732
  case "end":
701
- return _context4.stop();
733
+ return _context5.stop();
734
+ }
735
+ }, _callee5, this, [[10, 19]]);
736
+ }));
737
+ function getTimesheetHoursId(_x6, _x7) {
738
+ return _getTimesheetHoursId.apply(this, arguments);
739
+ }
740
+ return getTimesheetHoursId;
741
+ }();
742
+ _proto.getTimesheetHours = /*#__PURE__*/function () {
743
+ var _getTimesheetHours = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(workorderId) {
744
+ var _this = this;
745
+ var timesheetHourIds;
746
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
747
+ while (1) switch (_context7.prev = _context7.next) {
748
+ case 0:
749
+ _context7.next = 2;
750
+ return this.getTimesheetHoursIds(workorderId);
751
+ case 2:
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) {
757
+ case 0:
758
+ return _context6.abrupt("return", _this.axiosInstance.get("/services/data/" + SF_API_VERSION + "/sobjects/TimeSheetHour__c/" + id).then(function (res) {
759
+ return res.data;
760
+ }).then(toTimesheetDayEntry));
761
+ case 1:
762
+ case "end":
763
+ return _context6.stop();
764
+ }
765
+ }, _callee6);
766
+ }));
767
+ return function (_x9) {
768
+ return _ref2.apply(this, arguments);
769
+ };
770
+ }())));
771
+ case 4:
772
+ case "end":
773
+ return _context7.stop();
702
774
  }
703
- }, _callee4, this, [[9, 18]]);
775
+ }, _callee7, this);
704
776
  }));
705
- function getTimesheetHours(_x7, _x8, _x9, _x10) {
777
+ function getTimesheetHours(_x8) {
706
778
  return _getTimesheetHours.apply(this, arguments);
707
779
  }
708
780
  return getTimesheetHours;
709
781
  }();
710
782
  _proto.getPayPeriods = /*#__PURE__*/function () {
711
- var _getPayPeriods = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
783
+ var _getPayPeriods = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
712
784
  var url, query, data, payPeriods, _iterator3, _step3, payPeriod;
713
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
714
- while (1) switch (_context5.prev = _context5.next) {
785
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
786
+ while (1) switch (_context8.prev = _context8.next) {
715
787
  case 0:
716
788
  url = "/services/data/" + SF_API_VERSION + "/query";
717
789
  query = "SELECT Name,\n StartDate__c,\n EndDate__c\n FROM PayPeriod__c";
718
- _context5.next = 4;
790
+ _context8.next = 4;
719
791
  return this.axiosInstance.get(url, {
720
792
  params: {
721
793
  q: query
722
794
  }
723
795
  });
724
796
  case 4:
725
- data = _context5.sent;
797
+ data = _context8.sent;
726
798
  payPeriods = [];
727
799
  for (_iterator3 = _createForOfIteratorHelperLoose(data.data.records); !(_step3 = _iterator3()).done;) {
728
800
  payPeriod = _step3.value;
@@ -732,12 +804,12 @@ var SFTimesheetClient = /*#__PURE__*/function () {
732
804
  endDate: payPeriod.EndDate__c
733
805
  });
734
806
  }
735
- return _context5.abrupt("return", payPeriods);
807
+ return _context8.abrupt("return", payPeriods);
736
808
  case 8:
737
809
  case "end":
738
- return _context5.stop();
810
+ return _context8.stop();
739
811
  }
740
- }, _callee5, this);
812
+ }, _callee8, this);
741
813
  }));
742
814
  function getPayPeriods() {
743
815
  return _getPayPeriods.apply(this, arguments);
@@ -745,12 +817,12 @@ var SFTimesheetClient = /*#__PURE__*/function () {
745
817
  return getPayPeriods;
746
818
  }();
747
819
  _proto.uploadImageToTimesheet = /*#__PURE__*/function () {
748
- var _uploadImageToTimesheet = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(file, filename, timesheetId) {
749
- var form, uploadRes, versionId, _yield$this$axiosInst3, data, contentDocumentId, _err$response;
750
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
751
- while (1) switch (_context6.prev = _context6.next) {
820
+ var _uploadImageToTimesheet = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(file, filename, timesheetId) {
821
+ var form, uploadRes, versionId, _yield$this$axiosInst4, data, contentDocumentId, _err$response;
822
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
823
+ while (1) switch (_context9.prev = _context9.next) {
752
824
  case 0:
753
- _context6.prev = 0;
825
+ _context9.prev = 0;
754
826
  form = new FormData();
755
827
  form.append('entity_content', JSON.stringify({
756
828
  Title: filename,
@@ -762,24 +834,24 @@ var SFTimesheetClient = /*#__PURE__*/function () {
762
834
  filename: filename,
763
835
  contentType: 'application/octet-stream'
764
836
  });
765
- _context6.next = 6;
837
+ _context9.next = 6;
766
838
  return this.axiosInstance.post("/services/data/" + SF_API_VERSION + "/sobjects/ContentVersion", form, {
767
839
  headers: form.getHeaders()
768
840
  });
769
841
  case 6:
770
- uploadRes = _context6.sent;
842
+ uploadRes = _context9.sent;
771
843
  versionId = uploadRes.data.id; //get ContentDocumentId
772
- _context6.next = 10;
844
+ _context9.next = 10;
773
845
  return this.axiosInstance.get("/services/data/" + SF_API_VERSION + "/query", {
774
846
  params: {
775
847
  q: "SELECT ContentDocumentId FROM ContentVersion WHERE Id = '" + versionId + "'"
776
848
  }
777
849
  });
778
850
  case 10:
779
- _yield$this$axiosInst3 = _context6.sent;
780
- data = _yield$this$axiosInst3.data;
851
+ _yield$this$axiosInst4 = _context9.sent;
852
+ data = _yield$this$axiosInst4.data;
781
853
  contentDocumentId = data.records[0].ContentDocumentId;
782
- _context6.next = 15;
854
+ _context9.next = 15;
783
855
  return this.axiosInstance.post("/services/data/" + SF_API_VERSION + "/sobjects/ContentDocumentLink", {
784
856
  ContentDocumentId: contentDocumentId,
785
857
  LinkedEntityId: timesheetId,
@@ -787,20 +859,20 @@ var SFTimesheetClient = /*#__PURE__*/function () {
787
859
  Visibility: 'AllUsers'
788
860
  });
789
861
  case 15:
790
- _context6.next = 21;
862
+ _context9.next = 21;
791
863
  break;
792
864
  case 17:
793
- _context6.prev = 17;
794
- _context6.t0 = _context6["catch"](0);
795
- console.error('Salesforce error response:', _context6.t0 == null || (_err$response = _context6.t0.response) == null ? void 0 : _err$response.data);
796
- console.error('Error uploading and linking image:', _context6.t0 == null ? void 0 : _context6.t0.message);
865
+ _context9.prev = 17;
866
+ _context9.t0 = _context9["catch"](0);
867
+ console.error('Salesforce error response:', _context9.t0 == null || (_err$response = _context9.t0.response) == null ? void 0 : _err$response.data);
868
+ console.error('Error uploading and linking image:', _context9.t0 == null ? void 0 : _context9.t0.message);
797
869
  case 21:
798
870
  case "end":
799
- return _context6.stop();
871
+ return _context9.stop();
800
872
  }
801
- }, _callee6, this, [[0, 17]]);
873
+ }, _callee9, this, [[0, 17]]);
802
874
  }));
803
- function uploadImageToTimesheet(_x11, _x12, _x13) {
875
+ function uploadImageToTimesheet(_x10, _x11, _x12) {
804
876
  return _uploadImageToTimesheet.apply(this, arguments);
805
877
  }
806
878
  return uploadImageToTimesheet;