pha-hermes 1.15.0 → 1.16.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.
Files changed (42) hide show
  1. package/dist/api/liphe_legacy/assignment/assignmentClient.d.ts +28 -0
  2. package/dist/api/{liphe1.0 → liphe_legacy}/auth/authClient.d.ts +1 -1
  3. package/dist/api/liphe_legacy/contract_request/contractRequestClient.d.ts +80 -0
  4. package/dist/api/liphe_legacy/contract_request_period/contractRequestPeriodClient.d.ts +47 -0
  5. package/dist/api/{lipheApiClient.d.ts → liphe_legacy/lipheApiClient.d.ts} +4 -2
  6. package/dist/api/liphe_legacy/practitioner/practitionerClient.d.ts +7 -0
  7. package/dist/api/{apiClient.d.ts → salesforce/apiClient.d.ts} +2 -2
  8. package/dist/api/{payperiod → salesforce/payperiod}/payperiodClient.d.ts +1 -7
  9. package/dist/api/{practitioner → salesforce/practitioner}/practitionerClient.d.ts +1 -1
  10. package/dist/api/{timesheet → salesforce/timesheet}/timesheetClient.d.ts +1 -1
  11. package/dist/api/{workorder → salesforce/workorder}/workorderClient.d.ts +1 -1
  12. package/dist/index.d.ts +8 -8
  13. package/dist/models/index.d.ts +13 -17
  14. package/dist/models/{practitioner.d.ts → user.d.ts} +4 -0
  15. package/dist/models/workorder.d.ts +20 -0
  16. package/dist/pha-hermes.cjs.development.js +235 -3
  17. package/dist/pha-hermes.cjs.development.js.map +1 -1
  18. package/dist/pha-hermes.cjs.production.min.js +1 -1
  19. package/dist/pha-hermes.cjs.production.min.js.map +1 -1
  20. package/dist/pha-hermes.esm.js +237 -4
  21. package/dist/pha-hermes.esm.js.map +1 -1
  22. package/package.json +2 -1
  23. package/src/api/expenses/expenseClient.ts +1 -1
  24. package/src/api/liphe_legacy/assignment/assignmentClient.ts +67 -0
  25. package/src/api/{liphe1.0 → liphe_legacy}/auth/authClient.ts +11 -2
  26. package/src/api/liphe_legacy/contract_request/contractRequestClient.ts +128 -0
  27. package/src/api/liphe_legacy/contract_request_period/contractRequestPeriodClient.ts +233 -0
  28. package/src/api/{lipheApiClient.ts → liphe_legacy/lipheApiClient.ts} +23 -3
  29. package/src/api/{liphe1.0 → liphe_legacy}/practitioner/practitionerClient.ts +12 -4
  30. package/src/api/{apiClient.ts → salesforce/apiClient.ts} +2 -2
  31. package/src/api/{payperiod → salesforce/payperiod}/payperiodClient.ts +1 -8
  32. package/src/api/{practitioner → salesforce/practitioner}/practitionerClient.ts +1 -1
  33. package/src/api/{timesheet → salesforce/timesheet}/timesheetClient.ts +1 -1
  34. package/src/api/{workorder → salesforce/workorder}/workorderClient.ts +1 -1
  35. package/src/index.ts +13 -8
  36. package/src/models/index.ts +13 -18
  37. package/src/models/{practitioner.ts → user.ts} +5 -0
  38. package/src/models/workorder.ts +21 -0
  39. package/dist/api/liphe1.0/practitioner/practitionerClient.d.ts +0 -13
  40. package/src/api/.env +0 -5
  41. /package/dist/api/{auth → salesforce/auth}/auth.d.ts +0 -0
  42. /package/src/api/{auth → salesforce/auth}/auth.ts +0 -0
@@ -0,0 +1,28 @@
1
+ import { AxiosInstance } from 'axios';
2
+ export interface LipheAssignment {
3
+ id: number;
4
+ request_id: number;
5
+ dates_start: Date;
6
+ dates_end: Date;
7
+ shift: 'morning' | 'afternoon' | 'evening' | 'night';
8
+ time_start: Date;
9
+ time_end: Date;
10
+ status: 'draft' | 'inprogress' | 'approved' | 'rejected';
11
+ selected_client: Record<string, any>;
12
+ approver: string;
13
+ cost_covered: number | null;
14
+ travel: number | null;
15
+ lodging: number | null;
16
+ meal: number | null;
17
+ others: number | null;
18
+ modified_by: string | null;
19
+ created_at: Date;
20
+ updated_at: Date;
21
+ }
22
+ export declare class AssignmentClient {
23
+ private axiosInstance;
24
+ constructor(axiosInstance: AxiosInstance);
25
+ fetchAllAssignments(agencyId?: number, from?: Date, to?: Date, assignedPractitionerId?: string, page?: number, page_size?: number): Promise<LipheAssignment[]>;
26
+ fetchAssignment(assignmentId: string): Promise<LipheAssignment>;
27
+ createAssignment(assignment: LipheAssignment): Promise<LipheAssignment>;
28
+ }
@@ -7,7 +7,7 @@ export declare class LipheAuthenticator {
7
7
  private email;
8
8
  private password;
9
9
  private type;
10
- constructor(authenticatedAxiosInstance: AxiosInstance, baseUrl: string, email: string, password: string, type?: string);
10
+ constructor(authenticatedAxiosInstance: AxiosInstance, baseUrl: string, email: string, password: string, type?: 'user' | 'client');
11
11
  initializeAuth(): Promise<void>;
12
12
  private login;
13
13
  }
@@ -0,0 +1,80 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Workorder } from '../../../models';
3
+ export interface LipheContractRequest {
4
+ id: number;
5
+ name: string;
6
+ po_number: string | null;
7
+ level: string;
8
+ deadline: string;
9
+ from: string;
10
+ by: string;
11
+ by_value: string;
12
+ date: Date;
13
+ email_request: string;
14
+ type_of_request: string;
15
+ status: string;
16
+ is_deleted: number;
17
+ created_at: Date;
18
+ updated_at: Date;
19
+ created_by: string;
20
+ updated_by: string;
21
+ community_id: number;
22
+ agency_id: number;
23
+ contract_id: number;
24
+ job_id: number;
25
+ start_date: Date;
26
+ end_date: Date;
27
+ department_id: number | null;
28
+ job: LipheJob;
29
+ community: LipheCommunity;
30
+ }
31
+ interface LipheJob {
32
+ id: number;
33
+ code_nethris: number;
34
+ translations: LipheJobTranslation[];
35
+ }
36
+ interface LipheJobTranslation {
37
+ id: number;
38
+ translatable_type: string;
39
+ translatable_id: number;
40
+ column: string;
41
+ content: string;
42
+ locale: string;
43
+ created_at: Date;
44
+ updated_at: Date;
45
+ }
46
+ interface LipheCommunity {
47
+ id: number;
48
+ name: string;
49
+ region: LipheRegion;
50
+ contact: LipheContact;
51
+ }
52
+ interface LipheRegion {
53
+ id: number;
54
+ translations: LipheRegionTranslation[];
55
+ }
56
+ interface LipheRegionTranslation {
57
+ id: number;
58
+ translatable_type: string;
59
+ translatable_id: number;
60
+ column: string;
61
+ content: string;
62
+ locale: string;
63
+ created_at: Date;
64
+ updated_at: Date;
65
+ }
66
+ interface LipheContact {
67
+ id: number;
68
+ address: string;
69
+ address_city: string;
70
+ address_zip: string;
71
+ address_country: string;
72
+ address_state: string;
73
+ phone: string;
74
+ }
75
+ export declare class ContractRequestClient {
76
+ private axiosInstance;
77
+ constructor(axiosInstance: AxiosInstance);
78
+ fetchAllContractRequests(agencyId: number, from?: Date, to?: Date, page?: number, page_size?: number): Promise<Workorder[]>;
79
+ }
80
+ export {};
@@ -0,0 +1,47 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Agency, Period, Workorder } from '../../../models';
3
+ import { LipheContractRequest } from '../contract_request/contractRequestClient';
4
+ import { LipheAssignment } from '../assignment/assignmentClient';
5
+ interface LipheContractRequestPeriodData {
6
+ id: number;
7
+ contract_request_id: number;
8
+ start_date: Date;
9
+ end_date: Date;
10
+ shift: 'morning' | 'afternoon' | 'evening' | 'night';
11
+ start_time: Date;
12
+ end_time: Date;
13
+ departement_id: number;
14
+ note: string;
15
+ assignment_id: number;
16
+ assignment_parent_id: number | null;
17
+ created_at: Date;
18
+ updated_at: Date;
19
+ contract_request: LipheContractRequest;
20
+ department: string | null;
21
+ assignment: LipheAssignment;
22
+ assigned_employee_details: UserDetails;
23
+ assignment_employee: any;
24
+ }
25
+ interface UserDetails {
26
+ id: number;
27
+ name: string;
28
+ email: string | null;
29
+ }
30
+ export declare class ContractRequestPeriodClient {
31
+ private axiosInstance;
32
+ constructor(axiosInstance: AxiosInstance);
33
+ fetchAllContractRequestPeriods(agencyId: Agency, from?: Date, to?: Date, page?: number, activeAssignationsOnly?: boolean, assignedPractitionerId?: string): Promise<Workorder[]>;
34
+ fetchContractRequestPeriod(workorderId: string): Promise<LipheContractRequestPeriodData>;
35
+ getPayPeriodDatesForPayPeriodId(payPeriodId: string): Promise<Period[]>;
36
+ private getRole;
37
+ /**
38
+ * Calculates the pay period day of week that comes before the start date
39
+ * @param firstPayPeriodDate The first pay period date from the agency
40
+ * @param startDate The start date to find the pay period before
41
+ * @returns The day of week (0-6, where 0 is Sunday) of the pay period before start_date
42
+ */
43
+ private getPayPeriodDayBeforeStartDate;
44
+ private getLastDayOfPayPeriod;
45
+ private calculateWeeksBetween;
46
+ }
47
+ export {};
@@ -1,11 +1,13 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { LiphePractitionerClient } from './liphe1.0/practitioner/practitionerClient';
2
+ import { LiphePractitionerClient } from './practitioner/practitionerClient';
3
+ import { ContractRequestPeriodClient } from './contract_request_period/contractRequestPeriodClient';
3
4
  export declare class LipheApiClient {
4
5
  private instance;
5
6
  private axiosInstance;
6
7
  private authenticator;
7
8
  practitionerClient: LiphePractitionerClient;
8
- constructor(baseUrl: string, email: string, password: string, type?: string);
9
+ contractRequestPeriodClient: ContractRequestPeriodClient;
10
+ constructor(baseUrl: string, email: string, password: string, type?: 'user' | 'client');
9
11
  init(): Promise<void>;
10
12
  setInstance(instance: LipheApiClient): void;
11
13
  getInstance(): LipheApiClient;
@@ -0,0 +1,7 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ import { Practitioner } from '../../../models';
3
+ export declare class LiphePractitionerClient {
4
+ private axios;
5
+ constructor(axiosInstance: AxiosInstance);
6
+ fetchAllPractitioners(agencyId?: number): Promise<Practitioner[]>;
7
+ }
@@ -1,9 +1,9 @@
1
1
  import { SFTimesheetClient } from './timesheet/timesheetClient';
2
2
  import { SFPractitionerClient } from './practitioner/practitionerClient';
3
- import { Role } from '../models';
3
+ import { Role } from '../../models';
4
4
  import { SFWorkorderClient } from './workorder/workorderClient';
5
5
  import { SFPayPeriodClient } from './payperiod/payperiodClient';
6
- import { SFExpenseClient } from './expenses/expenseClient';
6
+ import { SFExpenseClient } from '../expenses/expenseClient';
7
7
  export declare const SF_API_VERSION: string;
8
8
  export declare class SFApiClient {
9
9
  private instance;
@@ -1,11 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- export interface Period {
3
- payPeriodId: string;
4
- startDate: Date;
5
- endDate: Date;
6
- timesheetId?: string;
7
- workorderId?: string;
8
- }
2
+ import { Period } from '../../../models';
9
3
  export declare class SFPayPeriodClient {
10
4
  private axiosInstance;
11
5
  constructor(axiosInstance: AxiosInstance);
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { Practitioner } from '../../models';
2
+ import { Practitioner } from '../../../models';
3
3
  export declare class SFPractitionerClient {
4
4
  private axiosInstance;
5
5
  constructor(axiosInstance: AxiosInstance);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { AxiosInstance } from 'axios';
3
- import { TimesheetDayEntry } from '../../models';
3
+ import { TimesheetDayEntry } from '../../../models';
4
4
  interface SFTimesheetHourField {
5
5
  Id: string;
6
6
  Date__c: Date;
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { Workorder } from '../../models';
2
+ import { Workorder } from '../../../models';
3
3
  export declare class SFWorkorderClient {
4
4
  private axiosInstance;
5
5
  constructor(axiosInstance: AxiosInstance);
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export { SFApiClient } from './api/apiClient';
2
- export { SFPractitionerClient } from './api/practitioner/practitionerClient';
3
- export { SFTimesheetClient } from './api/timesheet/timesheetClient';
4
- export { SFAuthenticator } from './api/auth/auth';
5
- export { Practitioner, Role, TimesheetDayEntry, Workorder } from './models';
6
- export { LipheApiClient } from './api/lipheApiClient';
7
- export { LipheAuthenticator } from './api/liphe1.0/auth/authClient';
8
- export { LiphePractitionerClient } from './api/liphe1.0/practitioner/practitionerClient';
1
+ export { SFApiClient } from './api/salesforce/apiClient';
2
+ export { SFPractitionerClient } from './api/salesforce/practitioner/practitionerClient';
3
+ export { SFTimesheetClient } from './api/salesforce/timesheet/timesheetClient';
4
+ export { SFAuthenticator } from './api/salesforce/auth/auth';
5
+ export { LipheApiClient } from './api/liphe_legacy/lipheApiClient';
6
+ export { LipheAuthenticator } from './api/liphe_legacy/auth/authClient';
7
+ export { LiphePractitionerClient } from './api/liphe_legacy/practitioner/practitionerClient';
9
8
  export { SFExpenseClient } from './api/expenses/expenseClient';
9
+ export { Practitioner, Role, TimesheetDayEntry, Workorder, Agency, Period } from './models';
@@ -1,19 +1,15 @@
1
- export interface Role {
2
- label: string;
3
- value: string;
4
- }
5
- export interface Workorder {
6
- id: string;
7
- name: string;
8
- region: string;
9
- establishmentName: string;
10
- establishmentId: string;
11
- role: string;
12
- practitionerId: string;
13
- startDate: Date;
14
- endDate: Date;
15
- createdAt: Date;
16
- updatedAt: Date;
1
+ export declare enum Agency {
2
+ CHCA = "7",
3
+ CodeBleu = "5",
4
+ NordikOntario = "6",
5
+ PHA = "8",
6
+ PremierSoin = "1",
7
+ PremierSoinNordik = "3",
8
+ SolutionNursing = "4",
9
+ SolutionsStaffing = "9",
10
+ Transport = "2",
11
+ SSI = "99"
17
12
  }
18
13
  export * from './timesheet';
19
- export * from './practitioner';
14
+ export * from './user';
15
+ export * from './workorder';
@@ -5,3 +5,7 @@ export interface Practitioner {
5
5
  email: string;
6
6
  staffId: string;
7
7
  }
8
+ export interface Role {
9
+ label: string;
10
+ value: string;
11
+ }
@@ -0,0 +1,20 @@
1
+ export interface Period {
2
+ payPeriodId: string;
3
+ startDate: Date;
4
+ endDate: Date;
5
+ timesheetId?: string;
6
+ workorderId?: string;
7
+ }
8
+ export interface Workorder {
9
+ id: string;
10
+ name: string;
11
+ region: string;
12
+ establishmentName: string;
13
+ establishmentId: string;
14
+ role: string;
15
+ practitionerId?: string;
16
+ startDate: Date;
17
+ endDate: Date;
18
+ createdAt?: Date;
19
+ updatedAt?: Date;
20
+ }
@@ -6,6 +6,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var axios = _interopDefault(require('axios'));
8
8
  var FormData = _interopDefault(require('form-data'));
9
+ var axiosRetry = _interopDefault(require('axios-retry'));
9
10
 
10
11
  function _arrayLikeToArray(r, a) {
11
12
  (null == a || a > r.length) && (a = r.length);
@@ -1292,6 +1293,12 @@ var LipheAuthenticator = /*#__PURE__*/function () {
1292
1293
  this.token = undefined;
1293
1294
  this.tokenRefreshPromise = null;
1294
1295
  this.authenticatedAxiosInstance = authenticatedAxiosInstance;
1296
+ axiosRetry(this.axiosTokenInstance, {
1297
+ retries: 10,
1298
+ retryDelay: function retryDelay(retryCount) {
1299
+ return Math.min(1000 * Math.pow(2, retryCount - 1), 30000);
1300
+ }
1301
+ });
1295
1302
  this.email = email;
1296
1303
  this.password = password;
1297
1304
  this.type = type;
@@ -1380,7 +1387,7 @@ var LipheAuthenticator = /*#__PURE__*/function () {
1380
1387
  form.append('password', this.password);
1381
1388
  form.append('type', this.type);
1382
1389
  _context3.next = 6;
1383
- return this.axiosTokenInstance.post('/v2/signin', form, {
1390
+ return this.axiosTokenInstance.post('v2/signin', form, {
1384
1391
  headers: form.getHeaders()
1385
1392
  });
1386
1393
  case 6:
@@ -1431,7 +1438,7 @@ var LiphePractitionerClient = /*#__PURE__*/function () {
1431
1438
  break;
1432
1439
  }
1433
1440
  _context.next = 7;
1434
- return this.axios.get('/v2/employees', {
1441
+ return this.axios.get('v2/employees', {
1435
1442
  params: {
1436
1443
  agency_id: agencyId,
1437
1444
  page: page
@@ -1461,7 +1468,15 @@ var LiphePractitionerClient = /*#__PURE__*/function () {
1461
1468
  _context.next = 4;
1462
1469
  break;
1463
1470
  case 17:
1464
- return _context.abrupt("return", practitioners);
1471
+ return _context.abrupt("return", practitioners.map(function (p) {
1472
+ return {
1473
+ id: String(p.id),
1474
+ firstName: p.firstname,
1475
+ lastName: p.lastname,
1476
+ email: p.email,
1477
+ staffId: String(p.id)
1478
+ };
1479
+ }));
1465
1480
  case 18:
1466
1481
  case "end":
1467
1482
  return _context.stop();
@@ -1476,6 +1491,200 @@ var LiphePractitionerClient = /*#__PURE__*/function () {
1476
1491
  return LiphePractitionerClient;
1477
1492
  }();
1478
1493
 
1494
+ var ContractRequestPeriodClient = /*#__PURE__*/function () {
1495
+ function ContractRequestPeriodClient(axiosInstance) {
1496
+ this.axiosInstance = axiosInstance;
1497
+ }
1498
+ var _proto = ContractRequestPeriodClient.prototype;
1499
+ _proto.fetchAllContractRequestPeriods = /*#__PURE__*/function () {
1500
+ var _fetchAllContractRequestPeriods = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(agencyId, from, to, page, activeAssignationsOnly, assignedPractitionerId) {
1501
+ var url, params, periods, nextPage, response, _iterator, _step, period;
1502
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1503
+ while (1) switch (_context.prev = _context.next) {
1504
+ case 0:
1505
+ if (page === void 0) {
1506
+ page = 1;
1507
+ }
1508
+ if (activeAssignationsOnly === void 0) {
1509
+ activeAssignationsOnly = true;
1510
+ }
1511
+ url = "v2/contract-request-periods/agency/" + agencyId;
1512
+ params = new URLSearchParams();
1513
+ periods = [];
1514
+ nextPage = true;
1515
+ if (from) {
1516
+ params.append('from', from.toISOString().split('T')[0] + ' 00:00:00');
1517
+ }
1518
+ if (to) {
1519
+ params.append('to', to.toISOString().split('T')[0] + ' 23:59:59');
1520
+ }
1521
+ if (page) {
1522
+ params.append('page', page.toString());
1523
+ }
1524
+ if (activeAssignationsOnly) {
1525
+ params.append('active_assignations_only', activeAssignationsOnly ? '1' : '0');
1526
+ }
1527
+ if (assignedPractitionerId) {
1528
+ params.append('assigned_employee_id', assignedPractitionerId);
1529
+ }
1530
+ case 11:
1531
+ if (!nextPage) {
1532
+ _context.next = 21;
1533
+ break;
1534
+ }
1535
+ params.set('page', page.toString());
1536
+ _context.next = 15;
1537
+ return this.axiosInstance.get(url, {
1538
+ params: params
1539
+ });
1540
+ case 15:
1541
+ response = _context.sent;
1542
+ for (_iterator = _createForOfIteratorHelperLoose(response.data.data); !(_step = _iterator()).done;) {
1543
+ period = _step.value;
1544
+ periods.push({
1545
+ id: period.id.toString(),
1546
+ name: period.id.toString(),
1547
+ establishmentId: period.contract_request.community.id.toString(),
1548
+ region: period.contract_request.community.contact.address_state,
1549
+ establishmentName: period.contract_request.community.name,
1550
+ role: this.getRole(period),
1551
+ practitionerId: period.assignment.selected_client.id,
1552
+ startDate: new Date(period.start_date),
1553
+ endDate: new Date(period.end_date),
1554
+ createdAt: new Date(period.created_at),
1555
+ updatedAt: new Date(period.updated_at)
1556
+ });
1557
+ }
1558
+ nextPage = page < response.data.meta.last_page;
1559
+ page++;
1560
+ _context.next = 11;
1561
+ break;
1562
+ case 21:
1563
+ return _context.abrupt("return", periods);
1564
+ case 22:
1565
+ case "end":
1566
+ return _context.stop();
1567
+ }
1568
+ }, _callee, this);
1569
+ }));
1570
+ function fetchAllContractRequestPeriods(_x, _x2, _x3, _x4, _x5, _x6) {
1571
+ return _fetchAllContractRequestPeriods.apply(this, arguments);
1572
+ }
1573
+ return fetchAllContractRequestPeriods;
1574
+ }();
1575
+ _proto.fetchContractRequestPeriod = /*#__PURE__*/function () {
1576
+ var _fetchContractRequestPeriod = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(workorderId) {
1577
+ var url, params, response;
1578
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1579
+ while (1) switch (_context2.prev = _context2.next) {
1580
+ case 0:
1581
+ url = "v2/contract-request-periods/" + workorderId;
1582
+ params = new URLSearchParams();
1583
+ _context2.next = 4;
1584
+ return this.axiosInstance.get(url, {
1585
+ params: params
1586
+ });
1587
+ case 4:
1588
+ response = _context2.sent;
1589
+ return _context2.abrupt("return", response.data.data);
1590
+ case 6:
1591
+ case "end":
1592
+ return _context2.stop();
1593
+ }
1594
+ }, _callee2, this);
1595
+ }));
1596
+ function fetchContractRequestPeriod(_x7) {
1597
+ return _fetchContractRequestPeriod.apply(this, arguments);
1598
+ }
1599
+ return fetchContractRequestPeriod;
1600
+ }();
1601
+ _proto.getPayPeriodDatesForPayPeriodId = /*#__PURE__*/function () {
1602
+ var _getPayPeriodDatesForPayPeriodId = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(payPeriodId) {
1603
+ var period, payPeriods, firstPayPeriodDate, lastPayPeriodDate, weeksBetween, i, tempDate, startDate, endDate;
1604
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1605
+ while (1) switch (_context3.prev = _context3.next) {
1606
+ case 0:
1607
+ _context3.next = 2;
1608
+ return this.fetchContractRequestPeriod(payPeriodId);
1609
+ case 2:
1610
+ period = _context3.sent;
1611
+ payPeriods = [];
1612
+ firstPayPeriodDate = this.getPayPeriodDayBeforeStartDate(new Date(period.assignment.selected_client.agency.date_first_periode_paie), new Date(period.start_date));
1613
+ lastPayPeriodDate = this.getLastDayOfPayPeriod(new Date(firstPayPeriodDate), new Date(period.end_date)); // Calculate the number of weeks between lastPayPeriodDate and firstPayPeriodDate
1614
+ weeksBetween = this.calculateWeeksBetween(firstPayPeriodDate, lastPayPeriodDate);
1615
+ for (i = 0; i < weeksBetween; i++) {
1616
+ tempDate = new Date(firstPayPeriodDate);
1617
+ startDate = new Date(tempDate.setDate(tempDate.getDate() + 7 * i));
1618
+ endDate = new Date(tempDate.setDate(tempDate.getDate() + 6));
1619
+ payPeriods.push({
1620
+ payPeriodId: '',
1621
+ startDate: startDate.toISOString().split('T')[0],
1622
+ endDate: endDate.toISOString().split('T')[0],
1623
+ workorderId: payPeriodId
1624
+ });
1625
+ }
1626
+ return _context3.abrupt("return", payPeriods);
1627
+ case 9:
1628
+ case "end":
1629
+ return _context3.stop();
1630
+ }
1631
+ }, _callee3, this);
1632
+ }));
1633
+ function getPayPeriodDatesForPayPeriodId(_x8) {
1634
+ return _getPayPeriodDatesForPayPeriodId.apply(this, arguments);
1635
+ }
1636
+ return getPayPeriodDatesForPayPeriodId;
1637
+ }();
1638
+ _proto.getRole = function getRole(period) {
1639
+ if (period.contract_request.job.translations.length === 0) {
1640
+ return '';
1641
+ }
1642
+ if (period.contract_request.job.translations.length > 1) {
1643
+ var roleTranslation = period.contract_request.job.translations.find(function (translation) {
1644
+ return translation.locale === 'en';
1645
+ });
1646
+ return roleTranslation == null ? void 0 : roleTranslation.content;
1647
+ } else {
1648
+ return period.contract_request.job.translations[0].content;
1649
+ }
1650
+ }
1651
+ /**
1652
+ * Calculates the pay period day of week that comes before the start date
1653
+ * @param firstPayPeriodDate The first pay period date from the agency
1654
+ * @param startDate The start date to find the pay period before
1655
+ * @returns The day of week (0-6, where 0 is Sunday) of the pay period before start_date
1656
+ */;
1657
+ _proto.getPayPeriodDayBeforeStartDate = function getPayPeriodDayBeforeStartDate(firstPayPeriodDate, startDate) {
1658
+ var payPeriodDayOfWeek = firstPayPeriodDate.getDay();
1659
+ // Calculate the most recent pay period date that falls before start_date
1660
+ var tempDate = new Date(startDate);
1661
+ // Go back one week at a time until we find a date that matches the pay period day of week
1662
+ while (tempDate.getDay() !== payPeriodDayOfWeek) {
1663
+ tempDate.setDate(tempDate.getDate() - 1);
1664
+ }
1665
+ // If the calculated date is not before start_date, go back another week
1666
+ if (tempDate >= startDate) {
1667
+ tempDate.setDate(tempDate.getDate() - 7);
1668
+ }
1669
+ return tempDate;
1670
+ };
1671
+ _proto.getLastDayOfPayPeriod = function getLastDayOfPayPeriod(firstPayPeriodDate, endDate) {
1672
+ var tempDate = new Date(firstPayPeriodDate);
1673
+ // Go back one week at a time until we find a date that matches the pay period day of week
1674
+ while (endDate > tempDate) {
1675
+ tempDate.setDate(tempDate.getDate() + 7);
1676
+ }
1677
+ return tempDate;
1678
+ };
1679
+ _proto.calculateWeeksBetween = function calculateWeeksBetween(startDate, endDate) {
1680
+ var diffTime = Math.abs(endDate.getTime() - startDate.getTime());
1681
+ var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
1682
+ var weeks = Math.floor(diffDays / 7);
1683
+ return weeks;
1684
+ };
1685
+ return ContractRequestPeriodClient;
1686
+ }();
1687
+
1479
1688
  var LipheApiClient = /*#__PURE__*/function () {
1480
1689
  function LipheApiClient(baseUrl, email, password, type) {
1481
1690
  if (type === void 0) {
@@ -1485,7 +1694,17 @@ var LipheApiClient = /*#__PURE__*/function () {
1485
1694
  this.axiosInstance = axios.create();
1486
1695
  this.axiosInstance.defaults.baseURL = baseUrl;
1487
1696
  this.authenticator = new LipheAuthenticator(this.axiosInstance, baseUrl, email, password, type);
1697
+ axiosRetry(this.axiosInstance, {
1698
+ retries: 10,
1699
+ retryDelay: function retryDelay(retryCount) {
1700
+ return Math.min(1000 * Math.pow(2, retryCount - 1), 30000);
1701
+ },
1702
+ onRetry: function onRetry(retryCount, error) {
1703
+ console.log("Retry attempt " + retryCount + " failed: " + error.message);
1704
+ }
1705
+ });
1488
1706
  this.practitionerClient = new LiphePractitionerClient(this.axiosInstance);
1707
+ this.contractRequestPeriodClient = new ContractRequestPeriodClient(this.axiosInstance);
1489
1708
  }
1490
1709
  var _proto = LipheApiClient.prototype;
1491
1710
  _proto.init = /*#__PURE__*/function () {
@@ -1518,6 +1737,19 @@ var LipheApiClient = /*#__PURE__*/function () {
1518
1737
  return LipheApiClient;
1519
1738
  }();
1520
1739
 
1740
+ (function (Agency) {
1741
+ Agency["CHCA"] = "7";
1742
+ Agency["CodeBleu"] = "5";
1743
+ Agency["NordikOntario"] = "6";
1744
+ Agency["PHA"] = "8";
1745
+ Agency["PremierSoin"] = "1";
1746
+ Agency["PremierSoinNordik"] = "3";
1747
+ Agency["SolutionNursing"] = "4";
1748
+ Agency["SolutionsStaffing"] = "9";
1749
+ Agency["Transport"] = "2";
1750
+ Agency["SSI"] = "99";
1751
+ })(exports.Agency || (exports.Agency = {}));
1752
+
1521
1753
  exports.LipheApiClient = LipheApiClient;
1522
1754
  exports.LipheAuthenticator = LipheAuthenticator;
1523
1755
  exports.LiphePractitionerClient = LiphePractitionerClient;