import {
CITIZENSHIP_OPTIONS,
GENDER_OPTIONS,
LANGUAGE_OPTIONS,
MARITAL_STATUS_OPTIONS,
} from "../../common/constants.mjs";
import {
clearObj,
parseObject,
} from "../../common/utils.mjs";
import talenthr from "../../talenthr.app.mjs";
export default {
key: "talenthr-update-employee",
name: "Update Employee",
description: "Allows updating an existing employee's data in the system. [See the documentation](https://apidocs.talenthr.io/)",
version: "0.0.1",
type: "action",
props: {
talenthr,
employeeId: {
propDefinition: [
talenthr,
"employeeId",
],
},
firstName: {
propDefinition: [
talenthr,
"firstName",
],
},
lastName: {
propDefinition: [
talenthr,
"lastName",
],
},
email: {
propDefinition: [
talenthr,
"email",
],
},
reportsToEmployeeId: {
propDefinition: [
talenthr,
"employeeId",
],
label: "Reports To Employee Id",
description: "If the **Reports To Employee Id** is 'null' then the current employee will be the head of the company.",
optional: true,
},
ssn: {
type: "string",
label: "SSN",
description: "The social security number of the employee",
optional: true,
},
birthDate: {
type: "string",
label: "Birth Date",
description: "The birth date must be formatted as 'YYYY-MM-DD' and must be between now and 1930-01-01.",
optional: true,
},
personalEmail: {
type: "string",
label: "Personal Email",
description: "The email has to be unique (among personal emails).",
optional: true,
},
maritalStatus: {
type: "string",
label: "Marital Status",
description: "The marital status of the employee",
options: MARITAL_STATUS_OPTIONS,
optional: true,
},
gender: {
type: "string",
label: "Gender",
description: "The gender of the employee",
options: GENDER_OPTIONS,
optional: true,
},
nationality: {
propDefinition: [
talenthr,
"nationality",
],
optional: true,
},
citizenship: {
type: "string",
label: "Citizenship",
description: "The citizenship of the employee",
options: CITIZENSHIP_OPTIONS,
optional: true,
},
workPhone: {
type: "string",
label: "Work Phone",
description: "The phone number of the employee's work",
optional: true,
},
mobilePhone: {
type: "string",
label: "Mobile Phone",
description: "The mobile phone numbe of the employee",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "The phone numbe of the employee",
optional: true,
},
address: {
propDefinition: [
talenthr,
"address",
],
optional: true,
},
country: {
propDefinition: [
talenthr,
"country",
],
optional: true,
},
postalCode: {
type: "string",
label: "Postal Code",
description: "The postal code where the employee lives",
optional: true,
},
city: {
type: "string",
label: "City",
description: "The city where the employee lives",
optional: true,
},
emergencyContactFullName: {
type: "string",
label: "Emergency Contact Name",
description: "The emergency contact's full name",
optional: true,
},
emergencyContactRelationshipTypeId: {
propDefinition: [
talenthr,
"emergencyContactRelationshipTypeId",
],
optional: true,
},
emergencyContactPhone: {
type: "string",
label: "Emergency Contact Phone",
description: "The emergency contact's phone number",
optional: true,
},
emergencyContactAddress: {
type: "string",
label: "Emergency Contact Address",
description: "The emergency contact's address",
optional: true,
},
linkedInUrl: {
type: "string",
label: "LinkedIn",
description: "The URL of the linkedIn",
optional: true,
},
employeeNumber: {
type: "string",
label: "Employee Number",
description: "An external number of the employee",
optional: true,
},
passportNumber: {
type: "string",
label: "Passport Number",
description: "The number of the employee's passport",
optional: true,
},
passportIssuedDate: {
type: "string",
label: "Passport Issued Date",
description: "The issued date of the employee's passport. **Format YYYY-MM-DD**",
optional: true,
},
passportExpiryDate: {
type: "string",
label: "Passport Expiry Date",
description: "The expiry date of the employee's passport. **Format YYYY-MM-DD**",
optional: true,
},
passportIssuingCountry: {
type: "string",
label: "Passport Issue Country",
description: "The issuing country of the employee's passport",
optional: true,
},
visaType: {
type: "string",
label: "Visa Type",
description: "The type of the employee's visa",
optional: true,
},
visaNumber: {
type: "string",
label: "Visa Number",
description: "The number of the employee's visa",
optional: true,
},
visaExpiryDate: {
type: "string",
label: "Visa Expiry Date",
description: "The expiry date of the employee's visa. **Format YYYY-MM-DD**",
optional: true,
},
driverLicenseNumber: {
type: "string",
label: "Driver License Number",
description: "The number of the employee's driver license",
optional: true,
},
driverLicenseIssuedDate: {
type: "string",
label: "Driver License Issued Date",
description: "The issued date of the employee's driver license. **Format YYYY-MM-DD**",
optional: true,
},
driverLicenseExpiryDate: {
type: "string",
label: "Driver License Expiry Date",
description: "The expiry date of the employee's driver license. **Format YYYY-MM-DD**",
optional: true,
},
driverLicenseIssuingCountry: {
type: "string",
label: "Driver License Issue Country",
description: "The issuing country of the employee's driver license",
optional: true,
},
secAddress: {
type: "string",
label: "Second Address",
description: "An employee's aditional address",
optional: true,
},
secCity: {
type: "string",
label: "Second City",
description: "An employee's aditional city",
optional: true,
},
secPostalCode: {
type: "string",
label: "Second Postal Code",
description: "An employee's aditional postal code",
optional: true,
},
secCountry: {
type: "string",
label: "Second Country",
description: "An employee's aditional country",
optional: true,
},
twitterUrl: {
type: "string",
label: "Twitter",
description: "The employee's twitter URL",
optional: true,
},
facebookUrl: {
type: "string",
label: "Facebook",
description: "The employee's facebook URL",
optional: true,
},
instagramUrl: {
type: "string",
label: "Instagram",
description: "The employee's instagram URL",
optional: true,
},
pinterestUrl: {
type: "string",
label: "Pinterest",
description: "The employee's pinterest URL",
optional: true,
},
githubUrl: {
type: "string",
label: "Github",
description: "The employee's github URL",
optional: true,
},
behanceUrl: {
type: "string",
label: "Behance",
description: "The employee's behance URL",
optional: true,
},
skypeName: {
type: "string",
label: "Skype Name",
description: "The employee's skype name",
optional: true,
},
shirtSize: {
type: "string",
label: "Shirt Size",
description: "The size of the shirt the employee wears",
optional: true,
},
tShirtSize: {
type: "string",
label: "T-Shirt Size",
description: "The size of the t-shirt the employee wears",
optional: true,
},
hrLanguages: {
type: "integer[]",
label: "HR Languages",
description: "A list of language ids",
options: LANGUAGE_OPTIONS,
optional: true,
},
hrFamily: {
type: "string[]",
label: "HR Family",
description: "An array of family objects. Example: `{\"name\": \"Jhon Doe\", \"gender\": \"Male\", \"birth_date\": \"2001-10-10\", \"family_member_relationship_id\": \"1\" }`",
optional: true,
},
allergies: {
type: "string",
label: "Allergies",
description: "The employee's allegies",
optional: true,
},
},
async run({ $ }) {
const response = await this.talenthr.updateEmployee({
$,
employeeId: this.employeeId,
data: clearObj({
first_name: this.firstName,
last_name: this.lastName,
email: this.email,
ssn: this.ssn,
birth_date: this.birthDate,
personal_email: this.personalEmail,
marital_status: this.maritalStatus,
gender: this.gender,
nationality: this.nationality,
citizenship: this.citizenship,
work_phone: this.workPhone,
mobile_phone: this.mobilePhone,
phone: this.phone,
address: this.address,
country: this.country,
postal_code: this.postalCode,
city: this.city,
reports_to_employee_id: this.reportsToEmployeeId,
emergency_contact: {
full_name: this.emergencyContactFullName,
relationship_type_id: this.emergencyContactRelationshipTypeId,
phone: this.emergencyContactPhone,
address: this.emergencyContactAddress,
},
linked_in_url: this.linkedInUrl,
employee_number: this.employeeNumber,
passport_number: this.passportNumber,
passport_issued_date: this.passportIssuedDate,
passport_expiry_date: this.passportExpiryDate,
passport_issuing_country: this.passportIssuingCountry,
visa_type: this.visaType,
visa_number: this.visaNumber,
visa_expiry_date: this.visaExpiryDate,
driver_license_number: this.driverLicenseNumber,
driver_license_issued_date: this.driverLicenseIssuedDate,
driver_license_expiry_date: this.driverLicenseExpiryDate,
driver_license_issuing_country: this.driverLicenseIssuingCountry,
sec_address: this.secAddress,
sec_city: this.secCity,
sec_postal_code: this.secPostalCode,
sec_country: this.secCountry,
twitter_url: this.twitterUrl,
facebook_url: this.facebookUrl,
instagram_url: this.instagramUrl,
pinterest_url: this.pinterestUrl,
github_url: this.githubUrl,
behance_url: this.behanceUrl,
skype_name: this.skypeName,
shirt_size: this.shirtSize,
t_shirt_size: this.tShirtSize,
hr_languages: parseObject(this.hrLanguages),
hr_family: parseObject(this.hrFamily),
allergies: this.allergies,
}),
});
$.export("$summary", `Successfully updated employee ID ${this.employeeId}`);
return response;
},
};