|
| 1 | +import { ConfigurationError } from "@pipedream/platform"; |
| 2 | +import { parseError } from "../../common/utils.mjs"; |
1 | 3 | import kiwihr from "../../kiwihr.app.mjs"; |
2 | | -import { axios } from "@pipedream/platform"; |
3 | 4 |
|
4 | 5 | export default { |
5 | 6 | key: "kiwihr-create-employee", |
6 | 7 | name: "Create Employee", |
7 | 8 | description: "Add a new employee to kiwiHR. [See the documentation](https://api.kiwihr.com/api/docs/mutation.doc.html)", |
8 | | - version: "0.0.{{ts}}", |
| 9 | + version: "0.0.1", |
9 | 10 | type: "action", |
10 | 11 | props: { |
11 | 12 | kiwihr, |
12 | | - employeeName: { |
13 | | - type: "string", |
14 | | - label: "Employee Name", |
15 | | - description: "Name of the employee to add.", |
| 13 | + firstName: { |
| 14 | + propDefinition: [ |
| 15 | + kiwihr, |
| 16 | + "firstName", |
| 17 | + ], |
| 18 | + }, |
| 19 | + lastName: { |
| 20 | + propDefinition: [ |
| 21 | + kiwihr, |
| 22 | + "lastName", |
| 23 | + ], |
16 | 24 | }, |
17 | 25 | email: { |
18 | | - type: "string", |
19 | | - label: "Email", |
20 | | - description: "Email of the employee to add.", |
| 26 | + propDefinition: [ |
| 27 | + kiwihr, |
| 28 | + "email", |
| 29 | + ], |
| 30 | + }, |
| 31 | + workPhones: { |
| 32 | + propDefinition: [ |
| 33 | + kiwihr, |
| 34 | + "workPhones", |
| 35 | + ], |
| 36 | + optional: true, |
| 37 | + }, |
| 38 | + employmentStartDate: { |
| 39 | + propDefinition: [ |
| 40 | + kiwihr, |
| 41 | + "employmentStartDate", |
| 42 | + ], |
| 43 | + optional: true, |
| 44 | + }, |
| 45 | + aboutMe: { |
| 46 | + propDefinition: [ |
| 47 | + kiwihr, |
| 48 | + "aboutMe", |
| 49 | + ], |
| 50 | + optional: true, |
| 51 | + }, |
| 52 | + gender: { |
| 53 | + propDefinition: [ |
| 54 | + kiwihr, |
| 55 | + "gender", |
| 56 | + ], |
| 57 | + optional: true, |
| 58 | + }, |
| 59 | + managerId: { |
| 60 | + propDefinition: [ |
| 61 | + kiwihr, |
| 62 | + "managerId", |
| 63 | + ], |
| 64 | + optional: true, |
| 65 | + }, |
| 66 | + nationality: { |
| 67 | + propDefinition: [ |
| 68 | + kiwihr, |
| 69 | + "nationality", |
| 70 | + ], |
| 71 | + optional: true, |
| 72 | + }, |
| 73 | + teamIds: { |
| 74 | + propDefinition: [ |
| 75 | + kiwihr, |
| 76 | + "teamIds", |
| 77 | + ], |
| 78 | + optional: true, |
21 | 79 | }, |
22 | | - startDate: { |
23 | | - type: "string", |
24 | | - label: "Start Date", |
25 | | - description: "Start date of the employee to add. Format: YYYY-MM-DD", |
| 80 | + positionId: { |
| 81 | + propDefinition: [ |
| 82 | + kiwihr, |
| 83 | + "positionId", |
| 84 | + ], |
| 85 | + optional: true, |
| 86 | + }, |
| 87 | + locationId: { |
| 88 | + propDefinition: [ |
| 89 | + kiwihr, |
| 90 | + "locationId", |
| 91 | + ], |
| 92 | + optional: true, |
26 | 93 | }, |
27 | | - department: { |
| 94 | + birthDate: { |
28 | 95 | propDefinition: [ |
29 | 96 | kiwihr, |
30 | | - "department", |
| 97 | + "birthDate", |
31 | 98 | ], |
32 | 99 | optional: true, |
33 | 100 | }, |
34 | | - jobTitle: { |
35 | | - type: "string", |
36 | | - label: "Job Title", |
37 | | - description: "Job title of the employee. Optional.", |
| 101 | + personalPhone: { |
| 102 | + propDefinition: [ |
| 103 | + kiwihr, |
| 104 | + "personalPhone", |
| 105 | + ], |
38 | 106 | optional: true, |
39 | 107 | }, |
40 | | - location: { |
| 108 | + personalEmail: { |
41 | 109 | propDefinition: [ |
42 | 110 | kiwihr, |
43 | | - "location", |
| 111 | + "personalEmail", |
| 112 | + ], |
| 113 | + optional: true, |
| 114 | + }, |
| 115 | + addressStreet: { |
| 116 | + propDefinition: [ |
| 117 | + kiwihr, |
| 118 | + "addressStreet", |
| 119 | + ], |
| 120 | + optional: true, |
| 121 | + }, |
| 122 | + addressCity: { |
| 123 | + propDefinition: [ |
| 124 | + kiwihr, |
| 125 | + "addressCity", |
| 126 | + ], |
| 127 | + optional: true, |
| 128 | + }, |
| 129 | + addressState: { |
| 130 | + propDefinition: [ |
| 131 | + kiwihr, |
| 132 | + "addressState", |
| 133 | + ], |
| 134 | + optional: true, |
| 135 | + }, |
| 136 | + addressPostalCode: { |
| 137 | + propDefinition: [ |
| 138 | + kiwihr, |
| 139 | + "addressPostalCode", |
| 140 | + ], |
| 141 | + optional: true, |
| 142 | + }, |
| 143 | + addressCountry: { |
| 144 | + propDefinition: [ |
| 145 | + kiwihr, |
| 146 | + "addressCountry", |
| 147 | + ], |
| 148 | + optional: true, |
| 149 | + }, |
| 150 | + pronouns: { |
| 151 | + propDefinition: [ |
| 152 | + kiwihr, |
| 153 | + "pronouns", |
44 | 154 | ], |
45 | 155 | optional: true, |
46 | 156 | }, |
47 | 157 | }, |
48 | 158 | async run({ $ }) { |
49 | | - const data = { |
50 | | - employeeName: this.employeeName, |
51 | | - email: this.email, |
52 | | - startDate: this.startDate, |
53 | | - department: this.department, |
54 | | - jobTitle: this.jobTitle, |
55 | | - location: this.location, |
56 | | - }; |
| 159 | + try { |
| 160 | + const { |
| 161 | + kiwihr, |
| 162 | + addressStreet, |
| 163 | + addressCity, |
| 164 | + addressState, |
| 165 | + addressPostalCode, |
| 166 | + addressCountry, |
| 167 | + ...user |
| 168 | + } = this; |
| 169 | + |
| 170 | + const address = {}; |
| 171 | + if (addressStreet) address.street = addressStreet; |
| 172 | + if (addressCity) address.city = addressCity; |
| 173 | + if (addressState) address.state = addressState; |
| 174 | + if (addressPostalCode) address.postalCode = addressPostalCode; |
| 175 | + if (addressCountry) address.country = addressCountry; |
| 176 | + |
| 177 | + if (Object.keys(address)) { |
| 178 | + user.address = address; |
| 179 | + } |
57 | 180 |
|
58 | | - const response = await this.kiwihr.createEmployee(data); |
| 181 | + const response = await kiwihr.createEmployee({ |
| 182 | + user, |
| 183 | + }); |
59 | 184 |
|
60 | | - $.export("$summary", `Successfully created employee ${this.employeeName}`); |
61 | | - return response; |
| 185 | + $.export("$summary", `Successfully created employee ${this.firstName} ${this.lastName}`); |
| 186 | + return response; |
| 187 | + } catch ({ response }) { |
| 188 | + const error = parseError(response); |
| 189 | + throw new ConfigurationError(error); |
| 190 | + } |
62 | 191 | }, |
63 | 192 | }; |
0 commit comments