pha-hermes 1.22.0 → 1.24.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,6 +1,6 @@
1
1
  import { AxiosInstance } from 'axios'
2
- import { Practitioner } from '../../../models'
3
- import { SF_API_VERSION } from '../apiClient'
2
+ import { Practitioner, Role } from '../../../models'
3
+ import { SF_API_VERSION } from '../../../index'
4
4
 
5
5
  export class SFPractitionerClient {
6
6
  private axiosInstance: AxiosInstance
@@ -66,6 +66,35 @@ export class SFPractitionerClient {
66
66
  throw error
67
67
  }
68
68
  }
69
+
70
+ async fetchRoles(): Promise<Role[]> {
71
+ try {
72
+ const url = `/services/data/${SF_API_VERSION}/query`
73
+ const query = `SELECT Label, Value FROM PicklistValueInfo \
74
+ WHERE EntityParticle.EntityDefinition.QualifiedApiName = 'WorkOrder__c'\
75
+ AND EntityParticle.QualifiedApiName = 'ProfessionalDesignation__c' \
76
+ AND isActive = true`
77
+ return this.axiosInstance
78
+ .get(url, {
79
+ params: { q: query }
80
+ })
81
+ .then(({ data: { records } }) =>
82
+ records.map(
83
+ (record): Role => ({
84
+ label: record.Label,
85
+ value: record.Value
86
+ })
87
+ )
88
+ )
89
+ .catch(error => {
90
+ console.error('Error fetching roles: ', error.message)
91
+ throw error
92
+ })
93
+ } catch (error) {
94
+ console.error('Error fetching roles: ', error.message)
95
+ throw error
96
+ }
97
+ }
69
98
  }
70
99
 
71
100
  function toPractitioner(raw: any): Practitioner {
@@ -75,6 +104,6 @@ function toPractitioner(raw: any): Practitioner {
75
104
  lastName: raw.LastName__c,
76
105
  email: raw.Email__c,
77
106
  staffId: raw.StaffID__c,
78
- createdAt: raw.CreatedDate.replace(/\+0000$/, 'Z')
107
+ createdAt: raw.CreatedDate ? raw.CreatedDate.replace(/\+0000$/, 'Z') : undefined
79
108
  }
80
109
  }
@@ -1,6 +1,6 @@
1
1
  import { AxiosInstance } from 'axios'
2
2
  import { Price } from '../../../models/price'
3
- import { SF_API_VERSION } from '../apiClient'
3
+ import { SF_API_VERSION } from '../../../index'
4
4
 
5
5
  export class SFPriceClient {
6
6
  private axiosInstance: AxiosInstance
@@ -1,6 +1,6 @@
1
1
  import { AxiosInstance } from 'axios'
2
2
  import { TimesheetDayEntry } from '../../../models'
3
- import { SF_API_VERSION } from '../apiClient'
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(workorderId: string, periodStartDate?: Date, periodEndDate?: Date): Promise<string[]> {
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(workorderId: string, fields?: SFTimesheetHourFieldKeys[], periodStartDate?: Date, periodEndDate?: Date): Promise<TimesheetDayEntry[]> {
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)}`
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios'
2
- import { SF_API_VERSION } from '../apiClient'
2
+ import { SF_API_VERSION } from '../../../index'
3
3
  import { Workorder } from '../../../models'
4
4
 
5
5
  export class SFWorkorderClient {
@@ -46,14 +46,16 @@ export class SFWorkorderClient {
46
46
  LastModifiedDate,
47
47
  Unit__c,
48
48
  HealthAuthority__c,
49
- UnitPrice__r.Price__c
49
+ UnitPrice__r.Price__c,
50
+ TravelDate__c,
51
+ ReturnDate__c
50
52
  FROM WorkOrder__c ${whereClause}`
51
53
  return await this.axiosInstance
52
54
  .get(url, {
53
55
  params: { q: query }
54
56
  })
55
- .then(({ data: { records } }) =>
56
- records.map(
57
+ .then(({ data: { records } }) => {
58
+ return records.map(
57
59
  (record): Workorder => ({
58
60
  id: record.Id,
59
61
  name: record.Name,
@@ -70,10 +72,12 @@ export class SFWorkorderClient {
70
72
  externalUnitId: formatId(record.Unit__c),
71
73
  healthAuthority: formatString(record.HealthAuthority__c),
72
74
  externalHealthAuthorityId: formatId(record.HealthAuthority__c),
73
- price: record.UnitPrice__r.Price__c
75
+ price: record.UnitPrice__r.Price__c,
76
+ travelInTime: new Date(record.TravelDate__c),
77
+ travelOutTime: new Date(record.ReturnDate__c)
74
78
  })
75
79
  )
76
- )
80
+ })
77
81
  } catch (error) {
78
82
  console.error('Error fetching work orders: ', error.message)
79
83
  throw error
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export const SF_API_VERSION: string = 'v57.0'
2
+
1
3
  // Salesforce API
2
4
  export { SFApiClient } from './api/salesforce/apiClient'
3
5
  export { SFPractitionerClient } from './api/salesforce/practitioner/practitionerClient'
@@ -23,4 +23,6 @@ export interface Workorder {
23
23
  healthAuthority?: string
24
24
  externalHealthAuthorityId?: string
25
25
  price?: string
26
+ travelInTime?: Date
27
+ travelOutTime?: Date
26
28
  }