Skip to content

Commit acf081b

Browse files
committed
Added actions
1 parent db457a5 commit acf081b

File tree

6 files changed

+264
-7
lines changed

6 files changed

+264
-7
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import app from "../../elorus.app.mjs";
2+
3+
export default {
4+
key: "elorus-create-task",
5+
name: "Create Task",
6+
description: "Create a new task in Elorus. [See the documentation](https://developer.elorus.com/#operation/tasks_create)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
propDefinition: [
13+
app,
14+
"name",
15+
],
16+
},
17+
description: {
18+
propDefinition: [
19+
app,
20+
"description",
21+
],
22+
},
23+
hourlyRate: {
24+
propDefinition: [
25+
app,
26+
"hourlyRate",
27+
],
28+
},
29+
project: {
30+
propDefinition: [
31+
app,
32+
"project",
33+
],
34+
},
35+
active: {
36+
propDefinition: [
37+
app,
38+
"active",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const response = await this.app.createTask({
44+
$,
45+
data: {
46+
name: this.name,
47+
description: this.description,
48+
hourly_rate: this.hourlyRate,
49+
project: this.project,
50+
active: this.active,
51+
},
52+
});
53+
$.export("$summary", "Successfully created the task with id: " + response.id);
54+
return response;
55+
},
56+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import app from "../../elorus.app.mjs";
2+
3+
export default {
4+
key: "elorus-delete-tasks",
5+
name: "Delete Tasks",
6+
description: "Delete a task from Elorus. [See the documentation](https://developer.elorus.com/#operation/tasks_delete)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
taskId: {
12+
propDefinition: [
13+
app,
14+
"taskId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.app.deleteTasks({
20+
$,
21+
taskId: this.taskId,
22+
});
23+
$.export("$summary", "Successfully deleted the task with ID: " + this.taskId);
24+
return response;
25+
},
26+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import app from "../../elorus.app.mjs";
2+
3+
export default {
4+
key: "elorus-get-tasks",
5+
name: "Get Tasks",
6+
description: "Get a list of tasks from Elorus. [See the documentation](https://developer.elorus.com/#operation/tasks_list)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
search: {
12+
propDefinition: [
13+
app,
14+
"search",
15+
],
16+
},
17+
project: {
18+
propDefinition: [
19+
app,
20+
"project",
21+
],
22+
},
23+
active: {
24+
propDefinition: [
25+
app,
26+
"active",
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const response = await this.app.getTasks({
32+
$,
33+
params: {
34+
search: this.search,
35+
project: this.project,
36+
active: this.active
37+
? 1
38+
: 0,
39+
},
40+
});
41+
$.export("$summary", "Successfully sent the request and retrieved " + response.results.length + " results");
42+
return response;
43+
},
44+
};

components/elorus/elorus.app.mjs

Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,134 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "elorus",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
name: {
8+
type: "string",
9+
label: "Name",
10+
description: "The name of the task",
11+
},
12+
description: {
13+
type: "string",
14+
label: "Description",
15+
description: "Short description of the task",
16+
optional: true,
17+
},
18+
hourlyRate: {
19+
type: "string",
20+
label: "Hourly Rate",
21+
description: "The hourly rate of the task",
22+
optional: true,
23+
},
24+
project: {
25+
type: "string",
26+
label: "Project",
27+
description: "The project associated with the task",
28+
async options() {
29+
const response = await this.getProjects();
30+
const projectsIds = response.results;
31+
return projectsIds.map(({
32+
id,
33+
name,
34+
}) => ({
35+
value: id,
36+
label: name,
37+
}));
38+
},
39+
optional: true,
40+
},
41+
active: {
42+
type: "boolean",
43+
label: "Active",
44+
description: "Specifies if the task is active",
45+
optional: true,
46+
},
47+
taskId: {
48+
type: "string",
49+
label: "Task Id",
50+
description: "The unique identifier of the task",
51+
async options({ page }) {
52+
try {
53+
const response = await this.getTasks({
54+
params: {
55+
"page": page + 1,
56+
"page_size": 100,
57+
},
58+
});
59+
const tasks = response.results || [];
60+
if (!tasks.length) {
61+
return [];
62+
}
63+
return tasks.map(({
64+
id, name,
65+
}) => ({
66+
value: id,
67+
label: name,
68+
}));
69+
} catch (err) {
70+
if (err.response?.data?.detail === "Invalid page.") {
71+
return [];
72+
}
73+
throw err;
74+
}
75+
},
76+
},
77+
search: {
78+
type: "string",
79+
label: "Search",
80+
description: "A search term",
81+
optional: true,
82+
},
83+
},
584
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
85+
_baseUrl() {
86+
return "https://api.elorus.com";
87+
},
88+
async _makeRequest(opts = {}) {
89+
const {
90+
$ = this,
91+
path,
92+
headers,
93+
...otherOpts
94+
} = opts;
95+
return axios($, {
96+
...otherOpts,
97+
url: this._baseUrl() + path,
98+
headers: {
99+
"Authorization": `Token ${this.$auth.api_key}`,
100+
"X-Elorus-Organization": `${this.$auth.organization_id}`,
101+
...headers,
102+
},
103+
});
104+
},
105+
async getTasks(args = {}) {
106+
return this._makeRequest({
107+
path: "/v1.2/tasks/",
108+
...args,
109+
});
110+
},
111+
async getProjects(args = {}) {
112+
return this._makeRequest({
113+
path: "/v1.2/projects/",
114+
...args,
115+
});
116+
},
117+
async deleteTasks({
118+
taskId, ...args
119+
}) {
120+
return this._makeRequest({
121+
path: `/v1.2/tasks/${taskId}/`,
122+
method: "delete",
123+
...args,
124+
});
125+
},
126+
async createTask(args = {}) {
127+
return this._makeRequest({
128+
path: "/v1.2/tasks/",
129+
method: "post",
130+
...args,
131+
});
9132
},
10133
},
11134
};

components/elorus/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
1518
}

pnpm-lock.yaml

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)