Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions components/talenthr/actions/create-employee/create-employee.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import {
OVERTIME_STATUS,
PAY_RATE_PERIOD_OPTIONS,
PAY_RATE_SCHEDULE_OPTIONS,
} from "../../common/constants.mjs";
import talenthr from "../../talenthr.app.mjs";

export default {
key: "talenthr-create-employee",
name: "Create Employee",
description: "Hires a new employee and registers them in the system. [See the documentation](https://apidocs.talenthr.io/#2950f0ba-b27b-4d4b-855f-4b79b667767c)",
version: "0.0.1",
type: "action",
props: {
talenthr,
firstName: {
propDefinition: [
talenthr,
"firstName",
],
},
lastName: {
propDefinition: [
talenthr,
"lastName",
],
},
email: {
propDefinition: [
talenthr,
"email",
],
},
hireDate: {
propDefinition: [
talenthr,
"hireDate",
],
},
employmentStatusId: {
propDefinition: [
talenthr,
"employmentStatusId",
],
},
reportsToEmployeeId: {
propDefinition: [
talenthr,
"employeeId",
],
optional: true,
},
jobTitleId: {
propDefinition: [
talenthr,
"jobTitleId",
],
optional: true,
},
jobLocationId: {
propDefinition: [
talenthr,
"jobLocationId",
],
optional: true,
},
divisionId: {
propDefinition: [
talenthr,
"divisionId",
],
optional: true,
},
departmentId: {
propDefinition: [
talenthr,
"departmentId",
],
optional: true,
},
payRate: {
type: "string",
label: "Pay Rate",
description: "Employee's wage and must have 2 decimals. E.g 1255.38",
},
Comment on lines +82 to +85
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider changing 'payRate' type to 'number'

Since payRate represents a numeric value, it would be more appropriate to set its type to "number" instead of "string". This ensures proper validation and handling of numerical input.

Apply this diff:

-        type: "string",
+        type: "number",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type: "string",
label: "Pay Rate",
description: "Employee's wage and must have 2 decimals. E.g 1255.38",
},
type: "number",
label: "Pay Rate",
description: "Employee's wage and must have 2 decimals. E.g 1255.38",
},

payRatePeriod: {
type: "string",
label: "Pay Rate Period",
description: "The period over which money is earned.",
options: PAY_RATE_PERIOD_OPTIONS,
},
payRateSchedule: {
type: "string",
label: "Pay Rate Schedule",
description: "Frequency of the wage.",
options: PAY_RATE_SCHEDULE_OPTIONS,
optional: true,
},
overtimeStatus: {
type: "string",
label: "Overtime Status",
description: "Determining whether an employee is exempt or non-exempt from overtime regulations.",
options: OVERTIME_STATUS,
optional: true,
},
preventEmail: {
type: "boolean",
label: "Prevent Email",
description: "Opt for 'true', if you don't want to send an invitation email to the hiring employee, else 'false'.",
optional: true,
},
isExisting: {
type: "boolean",
label: "Is Existing",
description: "Opt for 'false' if the employee is a new hire and you want to run the Automatic Onboarding process, else 'true'.",
optional: true,
},
whoId: {
type: "integer",
label: "Who Id",
description: "The employee who will meet the newly hired employee. Required if **When Time** and address is present.",
optional: true,
},
address: {
propDefinition: [
talenthr,
"address",
],
optional: true,
},
whenTime: {
type: "string",
label: "When Time",
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'.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Correct the description for 'whenTime' property

The description for whenTime incorrectly refers to "The hire date". It should refer to "The date and time" since it's about when the meeting will take place.

Apply this diff:

-          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'.",
+          description: "The date and time that the meeting will take place. Required if **Who Id** and address is present. The date and time must be formatted as 'YYYY-MM-DD HH:II'.",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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'.",
description: "The date and time that the meeting will take place. Required if **Who Id** and address is present. The date and time must be formatted as 'YYYY-MM-DD HH:II'.",

optional: true,
},
Comment on lines +119 to +136
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation for dependent fields 'whoId', 'whenTime', and 'address'

The properties whoId, whenTime, and address are interdependent. According to their descriptions, they are required if the others are present. Consider adding validation in the run method to ensure that if any of these fields are provided, all of them are present. This will prevent potential API errors due to incomplete hire_packet data.

You could add a validation check like this before making the API call:

if (
  (this.whoId || this.whenTime || this.address) &&
  !(this.whoId && this.whenTime && this.address)
) {
  throw new Error("When providing 'whoId', 'whenTime', or 'address', all three fields must be provided together.");
}

instructions: {
type: "string",
label: "Instructions",
description: "Important Instructions for the newly hired employee.",
optional: true,
},
},
async run({ $ }) {
const response = await this.talenthr.createEmployee({
$,
data: {
first_name: this.firstName,
last_name: this.lastName,
email: this.email,
hire_date: this.hireDate,
employment_status: {
employment_status_id: this.employmentStatusId,
},
reports_to_employee_id: this.reportsToEmployeeId,
job_record: {
job_title_id: this.jobTitleId,
location_id: this.jobLocationId,
division_id: this.divisionId,
department_id: this.departmentId,
},
compensation_record: {
pay_rate: parseFloat(this.payRate),
pay_rate_period: this.payRatePeriod,
pay_rate_schedule: this.payRateSchedule,
overtime_status: this.overtimeStatus,
},
prevent_email: this.preventEmail,
is_existing: this.isExisting,
hire_packet: {
who_id: this.whoId,
address: this.address,
when_time: this.whenTime,
instructions: this.instrwuctions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix typo in property value 'this.instrwuctions'

There's a typo in this.instrwuctions; it should be this.instructions.

Apply this diff to fix the typo:

-              instructions: this.instrwuctions,
+              instructions: this.instructions,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
instructions: this.instrwuctions,
instructions: this.instructions,

},
},
});

$.export("$summary", `Successfully created employee: ${response.data.id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import talenthr from "../../talenthr.app.mjs";

export default {
key: "talenthr-respond-time-off-request",
name: "Respond to Time Off Request",
description: "Responds to an employee's time off request. This action requires the request ID and the response status as props. [See the documentation](https://apidocs.talenthr.io/)",
version: "0.0.1",
type: "action",
props: {
talenthr,
employeeId: {
propDefinition: [
talenthr,
"employeeId",
],
},
timeOffRequestId: {
propDefinition: [
talenthr,
"timeOffRequestId",
({ employeeId }) => ({
employeeId,
}),
],
},
accept: {
type: "boolean",
label: "Accept",
description: "Approve 'true' or Reject 'false' the specified time off request. If the time off request has been answered or it has been cancelled then you cannot appove or reject it.",
},
},
async run({ $ }) {
const response = await this.talenthr.respondToTimeOffRequest({
timeOffRequestId: this.timeOffRequestId,
employeeId: this.employeeId,
data: {
accept: this.accept,
},
});

$.export("$summary", `Successfully responded to time off request with ID ${this.timeOffRequestId}`);
return response;
},
};
Loading
Loading