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.
- package/dist/api/timesheet/timesheetClient.d.ts +4 -24
- package/dist/pha-hermes.cjs.development.js +145 -73
- package/dist/pha-hermes.cjs.development.js.map +1 -1
- package/dist/pha-hermes.cjs.production.min.js +1 -1
- package/dist/pha-hermes.cjs.production.min.js.map +1 -1
- package/dist/pha-hermes.esm.js +145 -73
- package/dist/pha-hermes.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/api/.env +5 -0
- package/src/api/timesheet/timesheetClient.ts +50 -54
|
@@ -2,29 +2,6 @@ import { AxiosInstance } from 'axios'
|
|
|
2
2
|
import { TimesheetDayEntry } from '../../models'
|
|
3
3
|
import { SF_API_VERSION } from '../apiClient'
|
|
4
4
|
import FormData from 'form-data'
|
|
5
|
-
|
|
6
|
-
interface SFTimesheetHourField {
|
|
7
|
-
Id: string
|
|
8
|
-
Date__c: Date
|
|
9
|
-
Callback__c: number
|
|
10
|
-
HoursEBAdjusted__c: number
|
|
11
|
-
Misc__c: number
|
|
12
|
-
OT1__c: number
|
|
13
|
-
OT2__c: number
|
|
14
|
-
OnCall__c: number
|
|
15
|
-
Misc1__c: number
|
|
16
|
-
Misc_1_Hours__c: number
|
|
17
|
-
Misc_2_Hours__c: number
|
|
18
|
-
Misc_3_Hours__c: number
|
|
19
|
-
Misc_4_Hours__c: number
|
|
20
|
-
Stat1__c: number
|
|
21
|
-
Stat2__c: number
|
|
22
|
-
In_Charge__c: number
|
|
23
|
-
Shift_Travel_Stipend__c: number
|
|
24
|
-
LastModifiedDate: Date
|
|
25
|
-
}
|
|
26
|
-
type SFTimesheetHourFieldKeys = (keyof SFTimesheetHourField)[]
|
|
27
|
-
|
|
28
5
|
export class SFTimesheetClient {
|
|
29
6
|
private axiosInstance: AxiosInstance
|
|
30
7
|
|
|
@@ -61,23 +38,13 @@ export class SFTimesheetClient {
|
|
|
61
38
|
}
|
|
62
39
|
}
|
|
63
40
|
|
|
64
|
-
async
|
|
41
|
+
async getTimesheetId(workorderId: string): Promise<string> {
|
|
65
42
|
// Find all timesheet Ids that belong to this WO
|
|
66
43
|
const url = `/services/data/${SF_API_VERSION}/query`
|
|
67
|
-
|
|
44
|
+
const query = `SELECT Id
|
|
68
45
|
FROM Timesheet__c
|
|
69
|
-
WHERE WorkOrder__c = '${workorderId}'
|
|
70
|
-
|
|
71
|
-
if (periodStartDate && periodEndDate) {
|
|
72
|
-
query += `
|
|
73
|
-
AND PayPeriodStartDate__c <= ${new Date(periodStartDate).toISOString().substring(0, 10)}
|
|
74
|
-
AND PayPeriodEndDate__c >= ${new Date(periodEndDate).toISOString().substring(0, 10)}
|
|
75
|
-
`
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
console.error('Invalid period dates', error)
|
|
80
|
-
}
|
|
46
|
+
WHERE WorkOrder__c = '${workorderId}'
|
|
47
|
+
`
|
|
81
48
|
const {
|
|
82
49
|
data: { records }
|
|
83
50
|
} = await this.axiosInstance.get(url, {
|
|
@@ -110,34 +77,63 @@ export class SFTimesheetClient {
|
|
|
110
77
|
return timesheets
|
|
111
78
|
}
|
|
112
79
|
|
|
113
|
-
async
|
|
114
|
-
const timesheetIds = await this.
|
|
80
|
+
async getTimesheetHoursIds(workorderId: string): Promise<string[]> {
|
|
81
|
+
const timesheetIds = await this.getTimesheetId(workorderId)
|
|
82
|
+
const timesheetId = timesheetIds[0]
|
|
83
|
+
// First we find the correct timesheet hours id
|
|
84
|
+
const url = `/services/data/${SF_API_VERSION}/query`
|
|
85
|
+
const query = `SELECT Id
|
|
86
|
+
FROM TimesheetHour__c
|
|
87
|
+
WHERE Timesheet__c = '${timesheetId}'`
|
|
88
|
+
const {
|
|
89
|
+
data: { records }
|
|
90
|
+
} = await this.axiosInstance.get(url, {
|
|
91
|
+
params: { q: query }
|
|
92
|
+
})
|
|
93
|
+
return records.map(({ Id }) => Id)
|
|
94
|
+
}
|
|
115
95
|
|
|
116
|
-
|
|
96
|
+
async getTimesheetHoursId(workorderId: string, timesheetDate: Date): Promise<string[]> {
|
|
97
|
+
const timesheetIds = await this.getTimesheetId(workorderId)
|
|
98
|
+
const formattedDate = timesheetDate.toISOString().split('T')[0]
|
|
99
|
+
const allHourIds: string[] = []
|
|
117
100
|
const url = `/services/data/${SF_API_VERSION}/query`
|
|
101
|
+
|
|
118
102
|
for (const timesheetId of timesheetIds) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
103
|
+
const query = `
|
|
104
|
+
SELECT Id
|
|
105
|
+
FROM TimesheetHour__c
|
|
106
|
+
WHERE Timesheet__c = '${timesheetId}'
|
|
107
|
+
AND Date__c = ${formattedDate}
|
|
108
|
+
`
|
|
123
109
|
try {
|
|
124
|
-
if (fields?.length) {
|
|
125
|
-
query += `
|
|
126
|
-
AND Date__c >= ${new Date(periodStartDate).toISOString().substring(0, 10)}
|
|
127
|
-
AND Date__c <= ${new Date(periodEndDate).toISOString().substring(0, 10)}`
|
|
128
|
-
}
|
|
129
|
-
|
|
130
110
|
const {
|
|
131
111
|
data: { records }
|
|
132
|
-
} = await this.axiosInstance.get
|
|
112
|
+
} = await this.axiosInstance.get(url, {
|
|
133
113
|
params: { q: query }
|
|
134
114
|
})
|
|
135
|
-
|
|
115
|
+
|
|
116
|
+
const ids = records.map(record => record.Id)
|
|
117
|
+
allHourIds.push(...ids)
|
|
136
118
|
} catch (err) {
|
|
137
119
|
console.error(`Failed to fetch`, err)
|
|
120
|
+
return []
|
|
138
121
|
}
|
|
139
122
|
}
|
|
140
|
-
|
|
123
|
+
|
|
124
|
+
return allHourIds
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async getTimesheetHours(workorderId: string): Promise<TimesheetDayEntry[]> {
|
|
128
|
+
const timesheetHourIds = await this.getTimesheetHoursIds(workorderId)
|
|
129
|
+
return Promise.all(
|
|
130
|
+
timesheetHourIds.map(async id =>
|
|
131
|
+
this.axiosInstance
|
|
132
|
+
.get(`/services/data/${SF_API_VERSION}/sobjects/TimeSheetHour__c/${id}`)
|
|
133
|
+
.then(res => res.data)
|
|
134
|
+
.then(toTimesheetDayEntry)
|
|
135
|
+
)
|
|
136
|
+
)
|
|
141
137
|
}
|
|
142
138
|
|
|
143
139
|
async getPayPeriods(): Promise<any> {
|
|
@@ -218,7 +214,7 @@ export class SFTimesheetClient {
|
|
|
218
214
|
}
|
|
219
215
|
}
|
|
220
216
|
|
|
221
|
-
function toTimesheetDayEntry(raw:
|
|
217
|
+
function toTimesheetDayEntry(raw: any): TimesheetDayEntry {
|
|
222
218
|
return {
|
|
223
219
|
id: raw.Id,
|
|
224
220
|
date: raw.Date__c,
|