|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | + |
1 | 3 | export default { |
2 | 4 | type: "app", |
3 | 5 | app: "charthop", |
4 | | - propDefinitions: {}, |
| 6 | + version: "0.0.{{ts}}", |
| 7 | + propDefinitions: { |
| 8 | + // Event Filters for New Employee Added |
| 9 | + newEmployeeDepartmentFilter: { |
| 10 | + type: "string", |
| 11 | + label: "Department Filter", |
| 12 | + description: "Optional department filter for new employee events.", |
| 13 | + optional: true, |
| 14 | + }, |
| 15 | + newEmployeeRoleFilter: { |
| 16 | + type: "string", |
| 17 | + label: "Role Filter", |
| 18 | + description: "Optional role filter for new employee events.", |
| 19 | + optional: true, |
| 20 | + }, |
| 21 | + // Event Filters for Compensation Details Updated |
| 22 | + compensationDepartmentFilter: { |
| 23 | + type: "string", |
| 24 | + label: "Department Filter", |
| 25 | + description: "Optional department filter for compensation update events.", |
| 26 | + optional: true, |
| 27 | + }, |
| 28 | + compensationEmployeeIdFilter: { |
| 29 | + type: "string", |
| 30 | + label: "Employee ID Filter", |
| 31 | + description: "Optional employee ID filter for compensation update events.", |
| 32 | + optional: true, |
| 33 | + }, |
| 34 | + // Event Filters for Organizational Structure Changes |
| 35 | + orgStructureTeamFilter: { |
| 36 | + type: "string", |
| 37 | + label: "Team Filter", |
| 38 | + description: "Optional team filter for organizational structure change events.", |
| 39 | + optional: true, |
| 40 | + }, |
| 41 | + orgStructureDivisionFilter: { |
| 42 | + type: "string", |
| 43 | + label: "Division Filter", |
| 44 | + description: "Optional division filter for organizational structure change events.", |
| 45 | + optional: true, |
| 46 | + }, |
| 47 | + |
| 48 | + // Action: Add New Employee |
| 49 | + addEmployeeName: { |
| 50 | + type: "string", |
| 51 | + label: "Employee Name", |
| 52 | + description: "Name of the new employee.", |
| 53 | + }, |
| 54 | + addEmployeeEmail: { |
| 55 | + type: "string", |
| 56 | + label: "Employee Email", |
| 57 | + description: "Email address of the new employee.", |
| 58 | + }, |
| 59 | + addEmployeeRole: { |
| 60 | + type: "string", |
| 61 | + label: "Employee Role", |
| 62 | + description: "Role of the new employee.", |
| 63 | + }, |
| 64 | + addEmployeeStartDate: { |
| 65 | + type: "string", |
| 66 | + label: "Start Date", |
| 67 | + description: "Optional start date for the new employee.", |
| 68 | + optional: true, |
| 69 | + }, |
| 70 | + addEmployeeDepartment: { |
| 71 | + type: "string", |
| 72 | + label: "Department", |
| 73 | + description: "Optional department for the new employee.", |
| 74 | + optional: true, |
| 75 | + }, |
| 76 | + addEmployeeCustomFields: { |
| 77 | + type: "string[]", |
| 78 | + label: "Custom Fields", |
| 79 | + description: "Optional custom fields for the new employee. Provide as JSON strings.", |
| 80 | + optional: true, |
| 81 | + }, |
| 82 | + |
| 83 | + // Action: Update Employee Profile |
| 84 | + updateEmployeeId: { |
| 85 | + type: "string", |
| 86 | + label: "Employee ID", |
| 87 | + description: "ID of the employee to update.", |
| 88 | + }, |
| 89 | + updateFields: { |
| 90 | + type: "string[]", |
| 91 | + label: "Fields to Update", |
| 92 | + description: "Fields to update in the employee profile. Provide as JSON strings.", |
| 93 | + }, |
| 94 | + updateMetadata: { |
| 95 | + type: "string", |
| 96 | + label: "Metadata", |
| 97 | + description: "Optional metadata for the employee update. Provide as a JSON string.", |
| 98 | + optional: true, |
| 99 | + }, |
| 100 | + |
| 101 | + // Action: Modify Compensation Records |
| 102 | + modifyCompensationEmployeeId: { |
| 103 | + type: "string", |
| 104 | + label: "Employee ID", |
| 105 | + description: "ID of the employee for compensation update.", |
| 106 | + }, |
| 107 | + modifyCompensationDetails: { |
| 108 | + type: "string", |
| 109 | + label: "Compensation Details", |
| 110 | + description: "Details of the compensation update. Provide as a JSON string.", |
| 111 | + }, |
| 112 | + modifyCompensationEffectiveDate: { |
| 113 | + type: "string", |
| 114 | + label: "Effective Date", |
| 115 | + description: "Optional effective date for the compensation update.", |
| 116 | + optional: true, |
| 117 | + }, |
| 118 | + modifyCompensationReason: { |
| 119 | + type: "string", |
| 120 | + label: "Reason for Change", |
| 121 | + description: "Optional reason for the compensation update.", |
| 122 | + optional: true, |
| 123 | + }, |
| 124 | + }, |
5 | 125 | methods: { |
6 | | - // this.$auth contains connected account data |
| 126 | + // Existing method |
7 | 127 | authKeys() { |
8 | 128 | console.log(Object.keys(this.$auth)); |
9 | 129 | }, |
| 130 | + |
| 131 | + _baseUrl() { |
| 132 | + return "https://api.charthop.com"; |
| 133 | + }, |
| 134 | + async _makeRequest(opts = {}) { |
| 135 | + const { |
| 136 | + $ = this, method = "GET", path = "/", headers, ...otherOpts |
| 137 | + } = opts; |
| 138 | + return axios($, { |
| 139 | + ...otherOpts, |
| 140 | + method, |
| 141 | + url: `${this._baseUrl()}${path}`, |
| 142 | + headers: { |
| 143 | + ...headers, |
| 144 | + "Authorization": `Bearer ${this.$auth.api_token}`, |
| 145 | + "Content-Type": "application/json", |
| 146 | + }, |
| 147 | + }); |
| 148 | + }, |
| 149 | + // Event: Emit New Employee Added Event |
| 150 | + async emitNewEmployeeAddedEvent(opts = {}) { |
| 151 | + const data = {}; |
| 152 | + if (this.newEmployeeDepartmentFilter) data.department = this.newEmployeeDepartmentFilter; |
| 153 | + if (this.newEmployeeRoleFilter) data.role = this.newEmployeeRoleFilter; |
| 154 | + return this._makeRequest({ |
| 155 | + method: "POST", |
| 156 | + path: "/events/new-employee-added", |
| 157 | + data, |
| 158 | + }); |
| 159 | + }, |
| 160 | + // Event: Emit Compensation Updated Event |
| 161 | + async emitCompensationUpdatedEvent(opts = {}) { |
| 162 | + const data = {}; |
| 163 | + if (this.compensationDepartmentFilter) data.department = this.compensationDepartmentFilter; |
| 164 | + if (this.compensationEmployeeIdFilter) data.employee_id = this.compensationEmployeeIdFilter; |
| 165 | + return this._makeRequest({ |
| 166 | + method: "POST", |
| 167 | + path: "/events/compensation-updated", |
| 168 | + data, |
| 169 | + }); |
| 170 | + }, |
| 171 | + // Event: Emit Organizational Structure Changed Event |
| 172 | + async emitOrgStructureChangedEvent(opts = {}) { |
| 173 | + const data = {}; |
| 174 | + if (this.orgStructureTeamFilter) data.team = this.orgStructureTeamFilter; |
| 175 | + if (this.orgStructureDivisionFilter) data.division = this.orgStructureDivisionFilter; |
| 176 | + return this._makeRequest({ |
| 177 | + method: "POST", |
| 178 | + path: "/events/org-structure-changed", |
| 179 | + data, |
| 180 | + }); |
| 181 | + }, |
| 182 | + |
| 183 | + // Action: Add New Employee |
| 184 | + async addEmployee(opts = {}) { |
| 185 | + const data = { |
| 186 | + name: this.addEmployeeName, |
| 187 | + email: this.addEmployeeEmail, |
| 188 | + role: this.addEmployeeRole, |
| 189 | + }; |
| 190 | + if (this.addEmployeeStartDate) data.start_date = this.addEmployeeStartDate; |
| 191 | + if (this.addEmployeeDepartment) data.department = this.addEmployeeDepartment; |
| 192 | + if (this.addEmployeeCustomFields) { |
| 193 | + data.custom_fields = this.addEmployeeCustomFields.map((field) => JSON.parse(field)); |
| 194 | + } |
| 195 | + return this._makeRequest({ |
| 196 | + method: "POST", |
| 197 | + path: "/employees", |
| 198 | + data, |
| 199 | + }); |
| 200 | + }, |
| 201 | + |
| 202 | + // Action: Update Employee Profile |
| 203 | + async updateEmployeeProfile(opts = {}) { |
| 204 | + const data = {}; |
| 205 | + if (this.updateFields) { |
| 206 | + data.fields_to_update = this.updateFields.map((field) => JSON.parse(field)); |
| 207 | + } |
| 208 | + if (this.updateMetadata) { |
| 209 | + data.metadata = JSON.parse(this.updateMetadata); |
| 210 | + } |
| 211 | + return this._makeRequest({ |
| 212 | + method: "PUT", |
| 213 | + path: `/employees/${this.updateEmployeeId}`, |
| 214 | + data, |
| 215 | + }); |
| 216 | + }, |
| 217 | + |
| 218 | + // Action: Modify Compensation Records |
| 219 | + async modifyCompensation(opts = {}) { |
| 220 | + const data = {}; |
| 221 | + if (this.modifyCompensationDetails) { |
| 222 | + data.compensation_details = JSON.parse(this.modifyCompensationDetails); |
| 223 | + } |
| 224 | + if (this.modifyCompensationEffectiveDate) { |
| 225 | + data.effective_date = this.modifyCompensationEffectiveDate; |
| 226 | + } |
| 227 | + if (this.modifyCompensationReason) { |
| 228 | + data.reason = this.modifyCompensationReason; |
| 229 | + } |
| 230 | + return this._makeRequest({ |
| 231 | + method: "PUT", |
| 232 | + path: `/employees/${this.modifyCompensationEmployeeId}/compensation`, |
| 233 | + data, |
| 234 | + }); |
| 235 | + }, |
10 | 236 | }, |
11 | 237 | }; |
0 commit comments