pha-hermes 1.11.0 → 1.12.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 +24 -4
- package/dist/pha-hermes.cjs.development.js +85 -151
- 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 +85 -151
- package/dist/pha-hermes.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/api/timesheet/timesheetClient.ts +68 -54
- package/src/api/.env +0 -5
|
@@ -2,6 +2,29 @@ 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
|
+
|
|
5
28
|
export class SFTimesheetClient {
|
|
6
29
|
private axiosInstance: AxiosInstance
|
|
7
30
|
|
|
@@ -38,13 +61,23 @@ export class SFTimesheetClient {
|
|
|
38
61
|
}
|
|
39
62
|
}
|
|
40
63
|
|
|
41
|
-
async
|
|
64
|
+
async getTimesheetIds(workorderId: string, periodStartDate?: Date, periodEndDate?: Date): Promise<string[]> {
|
|
42
65
|
// Find all timesheet Ids that belong to this WO
|
|
43
66
|
const url = `/services/data/${SF_API_VERSION}/query`
|
|
44
|
-
|
|
67
|
+
let query = `SELECT Id
|
|
45
68
|
FROM Timesheet__c
|
|
46
|
-
WHERE WorkOrder__c = '${workorderId}'
|
|
47
|
-
|
|
69
|
+
WHERE WorkOrder__c = '${workorderId}'`
|
|
70
|
+
try {
|
|
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
|
+
}
|
|
48
81
|
const {
|
|
49
82
|
data: { records }
|
|
50
83
|
} = await this.axiosInstance.get(url, {
|
|
@@ -77,63 +110,34 @@ export class SFTimesheetClient {
|
|
|
77
110
|
return timesheets
|
|
78
111
|
}
|
|
79
112
|
|
|
80
|
-
async
|
|
81
|
-
const timesheetIds = await this.
|
|
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
|
-
}
|
|
113
|
+
async getTimesheetHours(workorderId: string, fields?: SFTimesheetHourFieldKeys[], periodStartDate?: Date, periodEndDate?: Date): Promise<TimesheetDayEntry[]> {
|
|
114
|
+
const timesheetIds = await this.getTimesheetIds(workorderId, periodStartDate, periodEndDate)
|
|
95
115
|
|
|
96
|
-
|
|
97
|
-
const timesheetIds = await this.getTimesheetId(workorderId)
|
|
98
|
-
const formattedDate = timesheetDate.toISOString().split('T')[0]
|
|
99
|
-
const allHourIds: string[] = []
|
|
116
|
+
const allHours: SFTimesheetHourField[] = []
|
|
100
117
|
const url = `/services/data/${SF_API_VERSION}/query`
|
|
101
|
-
|
|
102
118
|
for (const timesheetId of timesheetIds) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
AND Date__c = ${formattedDate}
|
|
108
|
-
`
|
|
119
|
+
let query = `
|
|
120
|
+
SELECT ${fields?.join(',') || 'FIELDS(STANDARD)'}
|
|
121
|
+
FROM TimesheetHour__c
|
|
122
|
+
WHERE Timesheet__c = '${timesheetId}'`
|
|
109
123
|
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
|
+
|
|
110
130
|
const {
|
|
111
131
|
data: { records }
|
|
112
|
-
} = await this.axiosInstance.get(url, {
|
|
132
|
+
} = await this.axiosInstance.get<{ records: SFTimesheetHourField[] }>(url, {
|
|
113
133
|
params: { q: query }
|
|
114
134
|
})
|
|
115
|
-
|
|
116
|
-
const ids = records.map(record => record.Id)
|
|
117
|
-
allHourIds.push(...ids)
|
|
135
|
+
allHours.push(...records)
|
|
118
136
|
} catch (err) {
|
|
119
137
|
console.error(`Failed to fetch`, err)
|
|
120
|
-
return []
|
|
121
138
|
}
|
|
122
139
|
}
|
|
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
|
-
)
|
|
140
|
+
return allHours.map(toTimesheetDayEntry)
|
|
137
141
|
}
|
|
138
142
|
|
|
139
143
|
async getPayPeriods(): Promise<any> {
|
|
@@ -166,10 +170,19 @@ export class SFTimesheetClient {
|
|
|
166
170
|
): Promise<void> {
|
|
167
171
|
try {
|
|
168
172
|
const form = new FormData()
|
|
169
|
-
form.append(
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
form.append(
|
|
174
|
+
'entity_content',
|
|
175
|
+
JSON.stringify({
|
|
176
|
+
Title: filename,
|
|
177
|
+
PathOnClient: filename
|
|
178
|
+
}),
|
|
179
|
+
{ contentType: 'application/json' }
|
|
180
|
+
)
|
|
172
181
|
|
|
182
|
+
form.append('VersionData', file, {
|
|
183
|
+
filename,
|
|
184
|
+
contentType: 'application/octet-stream'
|
|
185
|
+
})
|
|
173
186
|
const uploadRes = await this.axiosInstance.post(
|
|
174
187
|
`/services/data/${SF_API_VERSION}/sobjects/ContentVersion`,
|
|
175
188
|
form,
|
|
@@ -199,12 +212,13 @@ export class SFTimesheetClient {
|
|
|
199
212
|
}
|
|
200
213
|
)
|
|
201
214
|
} catch (err) {
|
|
202
|
-
console.error('
|
|
215
|
+
console.error('Salesforce error response:', err?.response?.data)
|
|
216
|
+
console.error('Error uploading and linking image:', err?.message)
|
|
203
217
|
}
|
|
204
218
|
}
|
|
205
219
|
}
|
|
206
220
|
|
|
207
|
-
function toTimesheetDayEntry(raw:
|
|
221
|
+
function toTimesheetDayEntry(raw: SFTimesheetHourField): TimesheetDayEntry {
|
|
208
222
|
return {
|
|
209
223
|
id: raw.Id,
|
|
210
224
|
date: raw.Date__c,
|
package/src/api/.env
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
I THINK THIS ONE IS WRONG
|
|
2
|
-
SF_CLIENT_ID=3MVG9TZvGM_0NqB09H2fPRxeiDEsovly3D10kwNjOYJNTwBhMc5JHQgCdaSM.2N1V04tb_Tuyj_qktBPNueQd
|
|
3
|
-
SF_CLIENT_SECRET=6F4D40003CF5B156A2AD2BFAD384E74AA9FFFD574E8753EAC485E3C478C50F9F
|
|
4
|
-
GRANT_TYPE=client_credentials
|
|
5
|
-
SALESFORCE_URL=https://do0000000d247eaa--phealth.sandbox.my.salesforce.com
|