pha-hermes 1.23.0 → 1.25.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/salesforce/practitioner/practitionerClient.d.ts +9 -1
- package/dist/index.d.ts +1 -0
- package/dist/models/user.d.ts +13 -0
- package/dist/pha-hermes.cjs.development.js +101 -28
- 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 +101 -29
- package/dist/pha-hermes.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/api/.env +5 -0
- package/src/api/salesforce/expenses/expenseClient.ts +1 -1
- package/src/api/salesforce/payperiod/payperiodClient.ts +2 -2
- package/src/api/salesforce/practitioner/practitionerClient.ts +96 -6
- package/src/api/salesforce/prices/priceClient.ts +1 -1
- package/src/api/salesforce/timesheet/timesheetClient.ts +14 -6
- package/src/api/salesforce/workorder/workorderClient.ts +1 -1
- package/src/index.ts +2 -0
- package/src/models/user.ts +14 -0
|
@@ -1,18 +1,54 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios'
|
|
2
|
-
import { Practitioner } from '../../../models'
|
|
3
|
-
import { SF_API_VERSION } from '
|
|
2
|
+
import { Practitioner, PractitionerExport, Role } from '../../../models'
|
|
3
|
+
import { SF_API_VERSION } from '../../../index'
|
|
4
4
|
|
|
5
5
|
export class SFPractitionerClient {
|
|
6
|
+
private PRACTITIONER_FIELDS = {
|
|
7
|
+
default: ['Id', 'FirstName__c', 'LastName__c', 'Email__c', 'StaffID__c', 'CreatedDate'],
|
|
8
|
+
export: [
|
|
9
|
+
'Id',
|
|
10
|
+
'FirstName__c',
|
|
11
|
+
'LastName__c',
|
|
12
|
+
'Email__c',
|
|
13
|
+
'StaffID__c',
|
|
14
|
+
'CreatedDate',
|
|
15
|
+
'DaytimePhone__c',
|
|
16
|
+
'Status__c',
|
|
17
|
+
'ProfessionalDesignation__c',
|
|
18
|
+
'CANSocialInsuranceNumber__c',
|
|
19
|
+
'Date_of_Hire__c',
|
|
20
|
+
'DateApplied__c',
|
|
21
|
+
'Birthdate__c',
|
|
22
|
+
'MailingStreetAddress__c',
|
|
23
|
+
'MailingCity__c',
|
|
24
|
+
'MailingStateProvince__c',
|
|
25
|
+
'MailingZipPostalCode__c'
|
|
26
|
+
]
|
|
27
|
+
} as const
|
|
28
|
+
|
|
6
29
|
private axiosInstance: AxiosInstance
|
|
7
30
|
|
|
8
31
|
constructor(axiosInstance: AxiosInstance) {
|
|
9
32
|
this.axiosInstance = axiosInstance
|
|
10
33
|
}
|
|
11
34
|
|
|
35
|
+
async fetchPractitioners(options: {
|
|
36
|
+
createdAt?: string
|
|
37
|
+
limit?: number
|
|
38
|
+
forExport: true
|
|
39
|
+
}): Promise<PractitionerExport[]>
|
|
40
|
+
|
|
12
41
|
async fetchPractitioners(options?: {
|
|
13
42
|
createdAt?: string
|
|
14
43
|
limit?: number
|
|
15
|
-
|
|
44
|
+
forExport?: false | undefined
|
|
45
|
+
}): Promise<Practitioner[]>
|
|
46
|
+
|
|
47
|
+
async fetchPractitioners(options?: {
|
|
48
|
+
createdAt?: string
|
|
49
|
+
limit?: number
|
|
50
|
+
forExport?: boolean
|
|
51
|
+
}): Promise<Practitioner[] | PractitionerExport[]> {
|
|
16
52
|
try {
|
|
17
53
|
const conditions: string[] = [`Status__c = 'Active'`]
|
|
18
54
|
if (options?.createdAt) {
|
|
@@ -24,8 +60,14 @@ export class SFPractitionerClient {
|
|
|
24
60
|
? `LIMIT ${Math.floor(options.limit)}`
|
|
25
61
|
: ''
|
|
26
62
|
const url = `/services/data/${SF_API_VERSION}/query`
|
|
63
|
+
const fields = (
|
|
64
|
+
options?.forExport
|
|
65
|
+
? this.PRACTITIONER_FIELDS.export
|
|
66
|
+
: this.PRACTITIONER_FIELDS.default
|
|
67
|
+
).join(', ')
|
|
68
|
+
|
|
27
69
|
const query = `
|
|
28
|
-
SELECT
|
|
70
|
+
SELECT ${fields}
|
|
29
71
|
FROM Personnel__c
|
|
30
72
|
${whereClause}
|
|
31
73
|
ORDER BY CreatedDate ASC, StaffID__c ASC
|
|
@@ -37,7 +79,9 @@ export class SFPractitionerClient {
|
|
|
37
79
|
params: { q: query }
|
|
38
80
|
})
|
|
39
81
|
|
|
40
|
-
return
|
|
82
|
+
return options?.forExport
|
|
83
|
+
? records.map(toPractitionerExport)
|
|
84
|
+
: records.map(toPractitioner)
|
|
41
85
|
} catch (error) {
|
|
42
86
|
console.error('Error fetching practitioners: ', error.message)
|
|
43
87
|
throw error
|
|
@@ -66,6 +110,35 @@ export class SFPractitionerClient {
|
|
|
66
110
|
throw error
|
|
67
111
|
}
|
|
68
112
|
}
|
|
113
|
+
|
|
114
|
+
async fetchRoles(): Promise<Role[]> {
|
|
115
|
+
try {
|
|
116
|
+
const url = `/services/data/${SF_API_VERSION}/query`
|
|
117
|
+
const query = `SELECT Label, Value FROM PicklistValueInfo \
|
|
118
|
+
WHERE EntityParticle.EntityDefinition.QualifiedApiName = 'WorkOrder__c'\
|
|
119
|
+
AND EntityParticle.QualifiedApiName = 'ProfessionalDesignation__c' \
|
|
120
|
+
AND isActive = true`
|
|
121
|
+
return this.axiosInstance
|
|
122
|
+
.get(url, {
|
|
123
|
+
params: { q: query }
|
|
124
|
+
})
|
|
125
|
+
.then(({ data: { records } }) =>
|
|
126
|
+
records.map(
|
|
127
|
+
(record): Role => ({
|
|
128
|
+
label: record.Label,
|
|
129
|
+
value: record.Value
|
|
130
|
+
})
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
.catch(error => {
|
|
134
|
+
console.error('Error fetching roles: ', error.message)
|
|
135
|
+
throw error
|
|
136
|
+
})
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error('Error fetching roles: ', error.message)
|
|
139
|
+
throw error
|
|
140
|
+
}
|
|
141
|
+
}
|
|
69
142
|
}
|
|
70
143
|
|
|
71
144
|
function toPractitioner(raw: any): Practitioner {
|
|
@@ -75,6 +148,23 @@ function toPractitioner(raw: any): Practitioner {
|
|
|
75
148
|
lastName: raw.LastName__c,
|
|
76
149
|
email: raw.Email__c,
|
|
77
150
|
staffId: raw.StaffID__c,
|
|
78
|
-
createdAt: raw.CreatedDate.replace(/\+0000$/, 'Z')
|
|
151
|
+
createdAt: raw.CreatedDate ? raw.CreatedDate.replace(/\+0000$/, 'Z') : undefined
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function toPractitionerExport(raw: any): PractitionerExport {
|
|
156
|
+
return {
|
|
157
|
+
...toPractitioner(raw),
|
|
158
|
+
phone: raw.DaytimePhone__c,
|
|
159
|
+
status: raw.Status__c,
|
|
160
|
+
professionalDesignation: raw.ProfessionalDesignation__c,
|
|
161
|
+
SIN: raw.CANSocialInsuranceNumber__c,
|
|
162
|
+
hiringDate: raw.Date_of_Hire__c,
|
|
163
|
+
dateApplied: raw.DateApplied__c,
|
|
164
|
+
birthdate: raw.Birthdate__c,
|
|
165
|
+
mailingStreetAddress: raw.MailingStreetAddress__c,
|
|
166
|
+
mailingCity: raw.MailingCity__c,
|
|
167
|
+
mailingProvince: raw.MailingStateProvince__c,
|
|
168
|
+
mailingZip: raw.MailingZipPostalCode__c
|
|
79
169
|
}
|
|
80
170
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios'
|
|
2
2
|
import { TimesheetDayEntry } from '../../../models'
|
|
3
|
-
import { SF_API_VERSION } from '
|
|
3
|
+
import { SF_API_VERSION } from '../../../index'
|
|
4
4
|
import FormData from 'form-data'
|
|
5
5
|
|
|
6
6
|
interface SFTimesheetHourField {
|
|
@@ -61,7 +61,11 @@ export class SFTimesheetClient {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
async getTimesheetIds(
|
|
64
|
+
async getTimesheetIds(
|
|
65
|
+
workorderId: string,
|
|
66
|
+
periodStartDate?: Date,
|
|
67
|
+
periodEndDate?: Date
|
|
68
|
+
): Promise<string[]> {
|
|
65
69
|
// Find all timesheet Ids that belong to this WO
|
|
66
70
|
const url = `/services/data/${SF_API_VERSION}/query`
|
|
67
71
|
let query = `SELECT Id
|
|
@@ -74,8 +78,7 @@ export class SFTimesheetClient {
|
|
|
74
78
|
AND PayPeriodEndDate__c >= ${new Date(periodEndDate).toISOString().substring(0, 10)}
|
|
75
79
|
`
|
|
76
80
|
}
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
81
|
+
} catch (error) {
|
|
79
82
|
console.error('Invalid period dates', error)
|
|
80
83
|
}
|
|
81
84
|
const {
|
|
@@ -110,7 +113,12 @@ export class SFTimesheetClient {
|
|
|
110
113
|
return timesheets
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
async getTimesheetHours(
|
|
116
|
+
async getTimesheetHours(
|
|
117
|
+
workorderId: string,
|
|
118
|
+
fields?: SFTimesheetHourFieldKeys[],
|
|
119
|
+
periodStartDate?: Date,
|
|
120
|
+
periodEndDate?: Date
|
|
121
|
+
): Promise<TimesheetDayEntry[]> {
|
|
114
122
|
const timesheetIds = await this.getTimesheetIds(workorderId, periodStartDate, periodEndDate)
|
|
115
123
|
|
|
116
124
|
const allHours: SFTimesheetHourField[] = []
|
|
@@ -121,7 +129,7 @@ export class SFTimesheetClient {
|
|
|
121
129
|
FROM TimesheetHour__c
|
|
122
130
|
WHERE Timesheet__c = '${timesheetId}'`
|
|
123
131
|
try {
|
|
124
|
-
if (fields?.length) {
|
|
132
|
+
if (fields?.length && periodStartDate && periodEndDate) {
|
|
125
133
|
query += `
|
|
126
134
|
AND Date__c >= ${new Date(periodStartDate).toISOString().substring(0, 10)}
|
|
127
135
|
AND Date__c <= ${new Date(periodEndDate).toISOString().substring(0, 10)}`
|
package/src/index.ts
CHANGED
package/src/models/user.ts
CHANGED
|
@@ -7,6 +7,20 @@ export interface Practitioner {
|
|
|
7
7
|
createdAt?: string
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export interface PractitionerExport extends Practitioner {
|
|
11
|
+
phone: string | null
|
|
12
|
+
status: string | null
|
|
13
|
+
professionalDesignation: string | null
|
|
14
|
+
SIN: string | null
|
|
15
|
+
hiringDate: string | null
|
|
16
|
+
dateApplied: string | null
|
|
17
|
+
birthdate: string | null
|
|
18
|
+
mailingStreetAddress: string | null
|
|
19
|
+
mailingCity: string | null
|
|
20
|
+
mailingProvince: string | null
|
|
21
|
+
mailingZip: string | null
|
|
22
|
+
}
|
|
23
|
+
|
|
10
24
|
export interface Role {
|
|
11
25
|
label: string
|
|
12
26
|
value: string
|