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
192 changes: 192 additions & 0 deletions components/kiwihr/actions/create-employee/create-employee.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { ConfigurationError } from "@pipedream/platform";
import { parseError } from "../../common/utils.mjs";
import kiwihr from "../../kiwihr.app.mjs";

export default {
key: "kiwihr-create-employee",
name: "Create Employee",
description: "Add a new employee to kiwiHR. [See the documentation](https://api.kiwihr.com/api/docs/mutation.doc.html)",
version: "0.0.1",
type: "action",
props: {
kiwihr,
firstName: {
propDefinition: [
kiwihr,
"firstName",
],
},
lastName: {
propDefinition: [
kiwihr,
"lastName",
],
},
email: {
propDefinition: [
kiwihr,
"email",
],
},
workPhones: {
propDefinition: [
kiwihr,
"workPhones",
],
optional: true,
},
employmentStartDate: {
propDefinition: [
kiwihr,
"employmentStartDate",
],
optional: true,
},
aboutMe: {
propDefinition: [
kiwihr,
"aboutMe",
],
optional: true,
},
gender: {
propDefinition: [
kiwihr,
"gender",
],
optional: true,
},
managerId: {
propDefinition: [
kiwihr,
"managerId",
],
optional: true,
},
nationality: {
propDefinition: [
kiwihr,
"nationality",
],
optional: true,
},
teamIds: {
propDefinition: [
kiwihr,
"teamIds",
],
optional: true,
},
positionId: {
propDefinition: [
kiwihr,
"positionId",
],
optional: true,
},
locationId: {
propDefinition: [
kiwihr,
"locationId",
],
optional: true,
},
birthDate: {
propDefinition: [
kiwihr,
"birthDate",
],
optional: true,
},
personalPhone: {
propDefinition: [
kiwihr,
"personalPhone",
],
optional: true,
},
personalEmail: {
propDefinition: [
kiwihr,
"personalEmail",
],
optional: true,
},
addressStreet: {
propDefinition: [
kiwihr,
"addressStreet",
],
optional: true,
},
addressCity: {
propDefinition: [
kiwihr,
"addressCity",
],
optional: true,
},
addressState: {
propDefinition: [
kiwihr,
"addressState",
],
optional: true,
},
addressPostalCode: {
propDefinition: [
kiwihr,
"addressPostalCode",
],
optional: true,
},
addressCountry: {
propDefinition: [
kiwihr,
"addressCountry",
],
optional: true,
},
pronouns: {
propDefinition: [
kiwihr,
"pronouns",
],
optional: true,
},
},
async run({ $ }) {
try {
const {
kiwihr,
addressStreet,
addressCity,
addressState,
addressPostalCode,
addressCountry,
...user
} = this;

const address = {};
if (addressStreet) address.street = addressStreet;
if (addressCity) address.city = addressCity;
if (addressState) address.state = addressState;
if (addressPostalCode) address.postalCode = addressPostalCode;
if (addressCountry) address.country = addressCountry;

if (Object.keys(address).length > 0) {
user.address = address;
}

const response = await kiwihr.createEmployee({
user,
});

$.export("$summary", `Successfully created employee ${this.firstName} ${this.lastName}`);
return response;
} catch ({ response }) {
const error = parseError(response);
throw new ConfigurationError(error);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import { ConfigurationError } from "@pipedream/platform";
import { parseError } from "../../common/utils.mjs";
import kiwihr from "../../kiwihr.app.mjs";

export default {
key: "kiwihr-update-employee-record",
name: "Update Employee Record",
description: "Update an existing employee's record in kiwiHR. [See the documentation](https://api.kiwihr.it/api/docs/mutation.doc.html)",
version: "0.0.1",
type: "action",
props: {
kiwihr,
employeeId: {
propDefinition: [
kiwihr,
"employeeId",
],
},
firstName: {
propDefinition: [
kiwihr,
"firstName",
],
optional: true,
},
lastName: {
propDefinition: [
kiwihr,
"lastName",
],
optional: true,
},
workPhones: {
propDefinition: [
kiwihr,
"workPhones",
],
optional: true,
},
employmentStartDate: {
propDefinition: [
kiwihr,
"employmentStartDate",
],
optional: true,
},
aboutMe: {
propDefinition: [
kiwihr,
"aboutMe",
],
optional: true,
},
gender: {
propDefinition: [
kiwihr,
"gender",
],
optional: true,
},
managerId: {
propDefinition: [
kiwihr,
"managerId",
],
optional: true,
},
nationality: {
propDefinition: [
kiwihr,
"nationality",
],
optional: true,
},
teamIds: {
propDefinition: [
kiwihr,
"teamIds",
],
optional: true,
},
positionId: {
propDefinition: [
kiwihr,
"positionId",
],
optional: true,
},
locationId: {
propDefinition: [
kiwihr,
"locationId",
],
optional: true,
},
birthDate: {
propDefinition: [
kiwihr,
"birthDate",
],
optional: true,
},
personalPhone: {
propDefinition: [
kiwihr,
"personalPhone",
],
optional: true,
},
personalEmail: {
propDefinition: [
kiwihr,
"personalEmail",
],
optional: true,
},
addressStreet: {
propDefinition: [
kiwihr,
"addressStreet",
],
optional: true,
},
addressCity: {
propDefinition: [
kiwihr,
"addressCity",
],
optional: true,
},
addressState: {
propDefinition: [
kiwihr,
"addressState",
],
optional: true,
},
addressPostalCode: {
propDefinition: [
kiwihr,
"addressPostalCode",
],
optional: true,
},
addressCountry: {
propDefinition: [
kiwihr,
"addressCountry",
],
optional: true,
},
pronouns: {
propDefinition: [
kiwihr,
"pronouns",
],
optional: true,
},
},
async run({ $ }) {
try {
const {
kiwihr,
employeeId,
addressStreet,
addressCity,
addressState,
addressPostalCode,
addressCountry,
...user
} = this;

const address = {};
if (addressStreet) address.street = addressStreet;
if (addressCity) address.city = addressCity;
if (addressState) address.state = addressState;
if (addressPostalCode) address.postalCode = addressPostalCode;
if (addressCountry) address.country = addressCountry;

if (Object.keys(address).length > 0) {
user.address = address;
}

const response = await kiwihr.updateEmployee({
id: employeeId,
user,
});

$.export("$summary", `Successfully updated employee record for ID: ${this.employeeId}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
$.export("$summary", `Successfully updated employee record for ID: ${this.employeeId}`);
$.export("$summary", `Successfully updated employee record for ID: ${employeeId}`);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not necessary, since I already got it on line 164

Copy link
Collaborator

Choose a reason for hiding this comment

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

That was my point. employeeId is already declared on line 164, so you don't need this in front of it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll move to QA since it doesn't affect functionality.

return response;
} catch ({ response }) {
const error = parseError(response);
throw new ConfigurationError(error);
}
},
};
7 changes: 7 additions & 0 deletions components/kiwihr/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const LIMIT = 100;

export const GENDER_OPTIONS = [
"MALE",
"FEMALE",
"DIVERSE",
];
Loading
Loading