Skip to content

Commit 6ac3fac

Browse files
committed
talenthr init
1 parent 2fab769 commit 6ac3fac

File tree

7 files changed

+369
-4
lines changed

7 files changed

+369
-4
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import talenthr from "../../talenthr.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "talenthr-create-employee",
6+
name: "Create Employee",
7+
description: "Hires a new employee and registers them in the system. [See the documentation](https://apidocs.talenthr.io/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
talenthr,
12+
name: {
13+
propDefinition: [
14+
talenthr,
15+
"name",
16+
],
17+
},
18+
role: {
19+
propDefinition: [
20+
talenthr,
21+
"role",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.talenthr.createEmployee({
27+
name: this.name,
28+
role: this.role,
29+
});
30+
31+
$.export("$summary", `Successfully created employee: ${response.name}`);
32+
return response;
33+
},
34+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import talenthr from "../../talenthr.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "talenthr-respond-time-off-request",
6+
name: "Respond to Time Off Request",
7+
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/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
talenthr,
12+
requestId: {
13+
propDefinition: [
14+
talenthr,
15+
"requestId",
16+
],
17+
},
18+
responseStatus: {
19+
propDefinition: [
20+
talenthr,
21+
"responseStatus",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.talenthr.respondToTimeOffRequest({
27+
requestId: this.requestId,
28+
responseStatus: this.responseStatus,
29+
});
30+
31+
$.export("$summary", `Successfully responded to time off request with ID ${this.requestId}`);
32+
return response;
33+
},
34+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import talenthr from "../../talenthr.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "talenthr-update-employee",
6+
name: "Update Employee",
7+
description: "Allows updating an existing employee's data in the system. [See the documentation](https://apidocs.talenthr.io/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
talenthr,
12+
employeeId: {
13+
propDefinition: [
14+
talenthr,
15+
"employeeId",
16+
],
17+
},
18+
dataFields: {
19+
propDefinition: [
20+
talenthr,
21+
"dataFields",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.talenthr.updateEmployee({
27+
employeeId: this.employeeId,
28+
dataFields: this.dataFields,
29+
});
30+
31+
$.export("$summary", `Successfully updated employee ID ${this.employeeId}`);
32+
return response;
33+
},
34+
};

components/talenthr/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { axios } from "@pipedream/platform";
2+
import talenthr from "../../talenthr.app.mjs";
3+
4+
export default {
5+
key: "talenthr-new-ats-application-instant",
6+
name: "New Job Application Submitted",
7+
description: "Emit new event when a new job application is submitted. [See the documentation](https://apidocs.talenthr.io/)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
talenthr,
13+
db: "$.service.db",
14+
jobPosition: {
15+
propDefinition: [
16+
talenthr,
17+
"jobPosition",
18+
],
19+
optional: true,
20+
},
21+
timer: {
22+
type: "$.interface.timer",
23+
default: {
24+
intervalSeconds: 60,
25+
},
26+
},
27+
},
28+
hooks: {
29+
async deploy() {
30+
const jobApplications = await this.talenthr.listNewJobApplications({
31+
jobPosition: this.jobPosition,
32+
});
33+
34+
jobApplications.slice(0, 50).forEach((application) => {
35+
this.$emit(application, {
36+
id: application.id,
37+
summary: `New Job Application: ${application.id}`,
38+
ts: Date.parse(application.created_at),
39+
});
40+
});
41+
},
42+
async activate() {},
43+
async deactivate() {},
44+
},
45+
methods: {
46+
_getLastChecked() {
47+
return this.db.get("lastChecked") || Date.now();
48+
},
49+
_setLastChecked(lastChecked) {
50+
this.db.set("lastChecked", lastChecked);
51+
},
52+
async emitApplicationEvents(applications) {
53+
for (const application of applications) {
54+
this.$emit(application, {
55+
id: application.id,
56+
summary: `New Job Application: ${application.id}`,
57+
ts: Date.parse(application.created_at),
58+
});
59+
}
60+
},
61+
},
62+
async run() {
63+
const lastChecked = this._getLastChecked();
64+
const jobPosition = this.jobPosition;
65+
const applications = await this.talenthr.listNewJobApplications({
66+
jobPosition,
67+
params: {
68+
since: new Date(lastChecked).toISOString(),
69+
},
70+
});
71+
await this.emitApplicationEvents(applications);
72+
this._setLastChecked(Date.now());
73+
},
74+
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import talenthr from "../../talenthr.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "talenthr-new-employee",
6+
name: "New Employee Created",
7+
description: "Emit new event whenever a new employee is created. [See the documentation](https://apidocs.talenthr.io/)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
talenthr,
13+
db: "$.service.db",
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: 60 * 10, // Poll every 10 minutes
18+
},
19+
},
20+
},
21+
hooks: {
22+
async deploy() {
23+
await this.processEvents();
24+
},
25+
async activate() {},
26+
async deactivate() {},
27+
},
28+
methods: {
29+
_getLastEmployeeId() {
30+
return this.db.get("lastEmployeeId");
31+
},
32+
_setLastEmployeeId(lastEmployeeId) {
33+
this.db.set("lastEmployeeId", lastEmployeeId);
34+
},
35+
async processEvents() {
36+
const lastEmployeeId = this._getLastEmployeeId();
37+
const params = lastEmployeeId
38+
? {
39+
since_id: lastEmployeeId,
40+
}
41+
: {};
42+
const employees = await this.talenthr.listNewEmployees({
43+
params,
44+
});
45+
46+
if (employees.length === 0) return;
47+
48+
let newLastEmployeeId = lastEmployeeId || 0;
49+
for (const employee of employees.reverse()) {
50+
if (employee.id > newLastEmployeeId) {
51+
this.$emit(employee, {
52+
id: employee.id,
53+
summary: `New Employee: ${employee.name}`,
54+
ts: new Date(employee.createdAt).getTime(),
55+
});
56+
newLastEmployeeId = employee.id;
57+
}
58+
}
59+
this._setLastEmployeeId(newLastEmployeeId);
60+
},
61+
},
62+
async run() {
63+
await this.processEvents();
64+
},
65+
};
Lines changed: 127 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,135 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "talenthr",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
jobPosition: {
8+
type: "string",
9+
label: "Job Position",
10+
description: "The job position for which the application has been submitted",
11+
async options() {
12+
const positions = await this.getJobPositions();
13+
return positions.map((position) => ({
14+
label: position.title,
15+
value: position.id,
16+
}));
17+
},
18+
},
19+
employeeId: {
20+
type: "string",
21+
label: "Employee ID",
22+
description: "The ID of the employee",
23+
},
24+
name: {
25+
type: "string",
26+
label: "Name",
27+
description: "The name of the new employee",
28+
},
29+
role: {
30+
type: "string",
31+
label: "Role",
32+
description: "The role of the new employee",
33+
},
34+
dataFields: {
35+
type: "object",
36+
label: "Data Fields",
37+
description: "The data fields to be updated for the employee",
38+
},
39+
requestId: {
40+
type: "string",
41+
label: "Request ID",
42+
description: "The ID of the time off request",
43+
},
44+
responseStatus: {
45+
type: "string",
46+
label: "Response Status",
47+
description: "The response status for the time off request",
48+
options: [
49+
"approved",
50+
"pending",
51+
"declined",
52+
],
53+
},
54+
},
555
methods: {
6-
// this.$auth contains connected account data
756
authKeys() {
857
console.log(Object.keys(this.$auth));
958
},
59+
_baseUrl() {
60+
return "https://api.talenthr.io";
61+
},
62+
async _makeRequest(opts = {}) {
63+
const {
64+
$ = this, method = "GET", path = "/", headers, ...otherOpts
65+
} = opts;
66+
return axios($, {
67+
...otherOpts,
68+
method,
69+
url: this._baseUrl() + path,
70+
headers: {
71+
...headers,
72+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
73+
},
74+
});
75+
},
76+
async getJobPositions(opts = {}) {
77+
return this._makeRequest({
78+
path: "/job-positions",
79+
...opts,
80+
});
81+
},
82+
async listNewEmployees(opts = {}) {
83+
return this._makeRequest({
84+
path: "/employees",
85+
...opts,
86+
});
87+
},
88+
async listNewJobApplications(opts = {}) {
89+
const {
90+
jobPosition, ...otherOpts
91+
} = opts;
92+
return this._makeRequest({
93+
path: jobPosition
94+
? `/job-applications?jobPosition=${jobPosition}`
95+
: "/job-applications",
96+
...otherOpts,
97+
});
98+
},
99+
async createEmployee(opts = {}) {
100+
return this._makeRequest({
101+
method: "POST",
102+
path: "/employees",
103+
data: {
104+
name: this.name,
105+
role: this.role,
106+
},
107+
...opts,
108+
});
109+
},
110+
async updateEmployee(opts = {}) {
111+
const {
112+
employeeId, dataFields, ...restOpts
113+
} = opts;
114+
return this._makeRequest({
115+
method: "PUT",
116+
path: `/employees/${employeeId}`,
117+
data: dataFields,
118+
...restOpts,
119+
});
120+
},
121+
async respondToTimeOffRequest(opts = {}) {
122+
const {
123+
requestId, responseStatus, ...restOpts
124+
} = opts;
125+
return this._makeRequest({
126+
method: "POST",
127+
path: `/time-off-requests/${requestId}/respond`,
128+
data: {
129+
status: responseStatus,
130+
},
131+
...restOpts,
132+
});
133+
},
10134
},
11-
};
135+
};

0 commit comments

Comments
 (0)