pha-hermes 1.7.0 → 1.9.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.
@@ -53,6 +53,21 @@ export class SFTimesheetClient {
53
53
  return records[0].Id
54
54
  }
55
55
 
56
+ async getTimesheetIds(workorderId: string): Promise<string[]> {
57
+ // Find all timesheet Ids that belong to this WO
58
+ const url = `/services/data/${SF_API_VERSION}/query`
59
+ const query = `SELECT Id
60
+ FROM Timesheet__c
61
+ WHERE WorkOrder__c = '${workorderId}'
62
+ `
63
+ const {
64
+ data: { records }
65
+ } = await this.axiosInstance.get(url, {
66
+ params: { q: query }
67
+ })
68
+ return records.map(record => record.Id)
69
+ }
70
+
56
71
  async getTimesheetsForPractitioner(personnelID: string) {
57
72
  const url = `/services/data/${SF_API_VERSION}/query`
58
73
 
@@ -92,6 +107,37 @@ export class SFTimesheetClient {
92
107
  return records.map(({ Id }) => Id)
93
108
  }
94
109
 
110
+ async getTimesheetHoursId(workorderId: string, timesheetDate: Date): Promise<string[]> {
111
+ const timesheetIds = await this.getTimesheetIds(workorderId)
112
+ const formattedDate = timesheetDate.toISOString().split('T')[0]
113
+ const allHourIds: string[] = []
114
+ const url = `/services/data/${SF_API_VERSION}/query`
115
+
116
+ for (const timesheetId of timesheetIds) {
117
+ const query = `
118
+ SELECT Id
119
+ FROM TimesheetHour__c
120
+ WHERE Timesheet__c = '${timesheetId}'
121
+ AND Date__c = ${formattedDate}
122
+ `
123
+ try {
124
+ const {
125
+ data: { records }
126
+ } = await this.axiosInstance.get(url, {
127
+ params: { q: query }
128
+ })
129
+
130
+ const ids = records.map(record => record.Id)
131
+ allHourIds.push(...ids)
132
+ } catch (err) {
133
+ console.error(`Failed to fetch`, err)
134
+ return []
135
+ }
136
+ }
137
+
138
+ return allHourIds
139
+ }
140
+
95
141
  async getTimesheetHours(workorderId: string): Promise<TimesheetDayEntry[]> {
96
142
  const timesheetHourIds = await this.getTimesheetHoursIds(workorderId)
97
143
  return Promise.all(