|  | 
|  | 1 | +import { | 
|  | 2 | +  OVERTIME_STATUS, | 
|  | 3 | +  PAY_RATE_PERIOD_OPTIONS, | 
|  | 4 | +  PAY_RATE_SCHEDULE_OPTIONS, | 
|  | 5 | +} from "../../common/constants.mjs"; | 
| 1 | 6 | import talenthr from "../../talenthr.app.mjs"; | 
| 2 |  | -import { axios } from "@pipedream/platform"; | 
| 3 | 7 | 
 | 
| 4 | 8 | export default { | 
| 5 | 9 |   key: "talenthr-create-employee", | 
| 6 | 10 |   name: "Create Employee", | 
| 7 |  | -  description: "Hires a new employee and registers them in the system. [See the documentation](https://apidocs.talenthr.io/)", | 
| 8 |  | -  version: "0.0.{{ts}}", | 
|  | 11 | +  description: "Hires a new employee and registers them in the system. [See the documentation](https://apidocs.talenthr.io/#2950f0ba-b27b-4d4b-855f-4b79b667767c)", | 
|  | 12 | +  version: "0.0.1", | 
| 9 | 13 |   type: "action", | 
| 10 | 14 |   props: { | 
| 11 | 15 |     talenthr, | 
| 12 |  | -    name: { | 
|  | 16 | +    firstName: { | 
| 13 | 17 |       propDefinition: [ | 
| 14 | 18 |         talenthr, | 
| 15 |  | -        "name", | 
|  | 19 | +        "firstName", | 
| 16 | 20 |       ], | 
| 17 | 21 |     }, | 
| 18 |  | -    role: { | 
|  | 22 | +    lastName: { | 
| 19 | 23 |       propDefinition: [ | 
| 20 | 24 |         talenthr, | 
| 21 |  | -        "role", | 
|  | 25 | +        "lastName", | 
| 22 | 26 |       ], | 
| 23 | 27 |     }, | 
|  | 28 | +    email: { | 
|  | 29 | +      propDefinition: [ | 
|  | 30 | +        talenthr, | 
|  | 31 | +        "email", | 
|  | 32 | +      ], | 
|  | 33 | +    }, | 
|  | 34 | +    hireDate: { | 
|  | 35 | +      propDefinition: [ | 
|  | 36 | +        talenthr, | 
|  | 37 | +        "hireDate", | 
|  | 38 | +      ], | 
|  | 39 | +    }, | 
|  | 40 | +    employmentStatusId: { | 
|  | 41 | +      propDefinition: [ | 
|  | 42 | +        talenthr, | 
|  | 43 | +        "employmentStatusId", | 
|  | 44 | +      ], | 
|  | 45 | +    }, | 
|  | 46 | +    reportsToEmployeeId: { | 
|  | 47 | +      propDefinition: [ | 
|  | 48 | +        talenthr, | 
|  | 49 | +        "employeeId", | 
|  | 50 | +      ], | 
|  | 51 | +      optional: true, | 
|  | 52 | +    }, | 
|  | 53 | +    jobTitleId: { | 
|  | 54 | +      propDefinition: [ | 
|  | 55 | +        talenthr, | 
|  | 56 | +        "jobTitleId", | 
|  | 57 | +      ], | 
|  | 58 | +      optional: true, | 
|  | 59 | +    }, | 
|  | 60 | +    jobLocationId: { | 
|  | 61 | +      propDefinition: [ | 
|  | 62 | +        talenthr, | 
|  | 63 | +        "jobLocationId", | 
|  | 64 | +      ], | 
|  | 65 | +      optional: true, | 
|  | 66 | +    }, | 
|  | 67 | +    divisionId: { | 
|  | 68 | +      propDefinition: [ | 
|  | 69 | +        talenthr, | 
|  | 70 | +        "divisionId", | 
|  | 71 | +      ], | 
|  | 72 | +      optional: true, | 
|  | 73 | +    }, | 
|  | 74 | +    departmentId: { | 
|  | 75 | +      propDefinition: [ | 
|  | 76 | +        talenthr, | 
|  | 77 | +        "departmentId", | 
|  | 78 | +      ], | 
|  | 79 | +      optional: true, | 
|  | 80 | +    }, | 
|  | 81 | +    payRate: { | 
|  | 82 | +      type: "string", | 
|  | 83 | +      label: "Pay Rate", | 
|  | 84 | +      description: "Employee's wage and must have 2 decimals. E.g 1255.38", | 
|  | 85 | +    }, | 
|  | 86 | +    payRatePeriod: { | 
|  | 87 | +      type: "string", | 
|  | 88 | +      label: "Pay Rate Period", | 
|  | 89 | +      description: "The period over which money is earned.", | 
|  | 90 | +      options: PAY_RATE_PERIOD_OPTIONS, | 
|  | 91 | +    }, | 
|  | 92 | +    payRateSchedule: { | 
|  | 93 | +      type: "string", | 
|  | 94 | +      label: "Pay Rate Schedule", | 
|  | 95 | +      description: "Frequency of the wage.", | 
|  | 96 | +      options: PAY_RATE_SCHEDULE_OPTIONS, | 
|  | 97 | +      optional: true, | 
|  | 98 | +    }, | 
|  | 99 | +    overtimeStatus: { | 
|  | 100 | +      type: "string", | 
|  | 101 | +      label: "Overtime Status", | 
|  | 102 | +      description: "Determining whether an employee is exempt or non-exempt from overtime regulations.", | 
|  | 103 | +      options: OVERTIME_STATUS, | 
|  | 104 | +      optional: true, | 
|  | 105 | +    }, | 
|  | 106 | +    preventEmail: { | 
|  | 107 | +      type: "boolean", | 
|  | 108 | +      label: "Prevent Email", | 
|  | 109 | +      description: "Opt for 'true', if you don't want to send an invitation email to the hiring employee, else 'false'.", | 
|  | 110 | +      optional: true, | 
|  | 111 | +    }, | 
|  | 112 | +    isExisting: { | 
|  | 113 | +      type: "boolean", | 
|  | 114 | +      label: "Is Existing", | 
|  | 115 | +      description: "Opt for 'false' if the employee is a new hire and you want to run the Automatic Onboarding process, else 'true'.", | 
|  | 116 | +      optional: true, | 
|  | 117 | +    }, | 
|  | 118 | +    whoId: { | 
|  | 119 | +      type: "integer", | 
|  | 120 | +      label: "Who Id", | 
|  | 121 | +      description: "The employee who will meet the newly hired employee. Required if **When Time** and address is present.", | 
|  | 122 | +      optional: true, | 
|  | 123 | +    }, | 
|  | 124 | +    address: { | 
|  | 125 | +      propDefinition: [ | 
|  | 126 | +        talenthr, | 
|  | 127 | +        "address", | 
|  | 128 | +      ], | 
|  | 129 | +      optional: true, | 
|  | 130 | +    }, | 
|  | 131 | +    whenTime: { | 
|  | 132 | +      type: "string", | 
|  | 133 | +      label: "When Time", | 
|  | 134 | +      description: "The date time that the meeting will take place. Required if **Who Id** and address is present. The hire date must be formatted as 'YYYY-MM-DD HH:II'.", | 
|  | 135 | +      optional: true, | 
|  | 136 | +    }, | 
|  | 137 | +    instructions: { | 
|  | 138 | +      type: "string", | 
|  | 139 | +      label: "Instructions", | 
|  | 140 | +      description: "Important Instructions for the newly hired employee.", | 
|  | 141 | +      optional: true, | 
|  | 142 | +    }, | 
| 24 | 143 |   }, | 
| 25 | 144 |   async run({ $ }) { | 
| 26 | 145 |     const response = await this.talenthr.createEmployee({ | 
| 27 |  | -      name: this.name, | 
| 28 |  | -      role: this.role, | 
|  | 146 | +      $, | 
|  | 147 | +      data: { | 
|  | 148 | +        first_name: this.firstName, | 
|  | 149 | +        last_name: this.lastName, | 
|  | 150 | +        email: this.email, | 
|  | 151 | +        hire_date: this.hireDate, | 
|  | 152 | +        employment_status: { | 
|  | 153 | +          employment_status_id: this.employmentStatusId, | 
|  | 154 | +        }, | 
|  | 155 | +        reports_to_employee_id: this.reportsToEmployeeId, | 
|  | 156 | +        job_record: { | 
|  | 157 | +          job_title_id: this.jobTitleId, | 
|  | 158 | +          location_id: this.jobLocationId, | 
|  | 159 | +          division_id: this.divisionId, | 
|  | 160 | +          department_id: this.departmentId, | 
|  | 161 | +        }, | 
|  | 162 | +        compensation_record: { | 
|  | 163 | +          pay_rate: parseFloat(this.payRate), | 
|  | 164 | +          pay_rate_period: this.payRatePeriod, | 
|  | 165 | +          pay_rate_schedule: this.payRateSchedule, | 
|  | 166 | +          overtime_status: this.overtimeStatus, | 
|  | 167 | +        }, | 
|  | 168 | +        prevent_email: this.preventEmail, | 
|  | 169 | +        is_existing: this.isExisting, | 
|  | 170 | +        hire_packet: { | 
|  | 171 | +          who_id: this.whoId, | 
|  | 172 | +          address: this.address, | 
|  | 173 | +          when_time: this.whenTime, | 
|  | 174 | +          instructions: this.instrwuctions, | 
|  | 175 | +        }, | 
|  | 176 | +      }, | 
| 29 | 177 |     }); | 
| 30 | 178 | 
 | 
| 31 |  | -    $.export("$summary", `Successfully created employee: ${response.name}`); | 
|  | 179 | +    $.export("$summary", `Successfully created employee: ${response.data.id}`); | 
| 32 | 180 |     return response; | 
| 33 | 181 |   }, | 
| 34 | 182 | }; | 
0 commit comments