Skip to content
64 changes: 64 additions & 0 deletions components/hubstaff/actions/create-task/create-task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ConfigurationError } from "@pipedream/platform";
import hubstaff from "../../hubstaff.app.mjs";

export default {
key: "hubstaff-create-task",
name: "Create Task",
description: "Creates a new task on your Hubstaff organization. [See the documentation](https://developer.hubstaff.com/docs/hubstaff_v2#!/tasks/postV2ProjectsProjectIdTasks)",
version: "0.0.1",
type: "action",
props: {
hubstaff,
organizationId: {
propDefinition: [
hubstaff,
"organizationId",
],
},
projectId: {
propDefinition: [
hubstaff,
"projectId",
({ organizationId }) => ({
organizationId,
}),
],
},
summary: {
propDefinition: [
hubstaff,
"summary",
],
},
assigneeId: {
propDefinition: [
hubstaff,
"userIds",
({ projectId }) => ({
projectId,
}),
],
type: "string",
label: "User ID",
description: "Assignee user ID for this task.",
},
},
async run({ $ }) {
try {
const response = await this.hubstaff.createTask({
$,
projectId: this.projectId,
data: {
summary: this.summary,
assignee_id: this.assigneeId,
},
});

$.export("$summary", `Successfully created task with ID ${response.task.id}`);
return response;
} catch ({ message }) {
const { error } = JSON.parse(message);
throw new ConfigurationError(error);
}
},
};
71 changes: 71 additions & 0 deletions components/hubstaff/actions/list-tasks/list-tasks.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { INCLUDE_OPTIONS } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import hubstaff from "../../hubstaff.app.mjs";

export default {
key: "hubstaff-list-tasks",
name: "List Tasks",
description: "Retrieves a list of all tasks from your Hubstaff organization. [See the documentation](https://developer.hubstaff.com/docs/hubstaff_v2#!/tasks/getV2OrganizationsOrganizationIdTasks)",
version: "0.0.1",
type: "action",
props: {
hubstaff,
organizationId: {
propDefinition: [
hubstaff,
"organizationId",
],
},
projectId: {
propDefinition: [
hubstaff,
"projectId",
({ organizationId }) => ({
organizationId,
}),
],
type: "string[]",
optional: true,
},
status: {
propDefinition: [
hubstaff,
"status",
],
type: "string[]",
optional: true,
},
userIds: {
propDefinition: [
hubstaff,
"userIds",
(c) => ({
organizationId: c.organizationId,
}),
],
optional: true,
},
include: {
type: "string[]",
label: "Include",
description: "Specify related data to side load.",
options: INCLUDE_OPTIONS,
optional: true,
},
},
async run({ $ }) {
const response = await this.hubstaff.listAllTasks({
$,
organizationId: this.organizationId,
params: {
include: parseObject(this.include),
project_ids: parseObject(this.projectId),
user_ids: parseObject(this.userIds),
status: parseObject(this.status),
},
});

$.export("$summary", `Successfully retrieved ${response.tasks.length} task(s)`);
return response;
},
};
95 changes: 95 additions & 0 deletions components/hubstaff/actions/update-task/update-task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { ConfigurationError } from "@pipedream/platform";
import hubstaff from "../../hubstaff.app.mjs";

export default {
key: "hubstaff-update-task",
name: "Update Task",
description: "Update a specific task within your Hubstaff organization. [See the documentation](https://developer.hubstaff.com/docs/hubstaff_v2#!/tasks/putV2TasksTaskId)",
version: "0.0.1",
type: "action",
props: {
hubstaff,
organizationId: {
propDefinition: [
hubstaff,
"organizationId",
],
},
projectId: {
propDefinition: [
hubstaff,
"projectId",
({ organizationId }) => ({
organizationId,
}),
],
},
taskId: {
propDefinition: [
hubstaff,
"taskId",
({
organizationId, projectId,
}) => ({
organizationId,
projectId,
}),
],
},
summary: {
propDefinition: [
hubstaff,
"summary",
],
},
assigneeId: {
propDefinition: [
hubstaff,
"userIds",
({ projectId }) => ({
projectId,
}),
],
type: "string",
label: "User ID",
description: "Assignee user ID for this task.",
},
status: {
propDefinition: [
hubstaff,
"status",
],
options: [
"active",
"completed",
],
optional: true,
},
lockVersion: {
type: "integer",
label: "Lock Version",
description: "The lock version from the task fetch in order to update.",
default: 0,
},
},
async run({ $ }) {
try {
const response = await this.hubstaff.updateTask({
$,
taskId: this.taskId,
data: {
summary: this.summary,
lock_version: this.lockVersion,
status: this.status,
assignee_id: this.assigneeId,
},
});

$.export("$summary", `Successfully updated task with ID ${this.taskId}`);
return response;
} catch ({ message }) {
const { error } = JSON.parse(message);
throw new ConfigurationError(error);
}
},
};
41 changes: 41 additions & 0 deletions components/hubstaff/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export const INCLUDE_OPTIONS = [
{
label: "Users",
value: "users",
},
{
label: "Projects",
value: "projects",
},
];

export const STATUS_OPTIONS = [
{
value: "active",
label: "Active",
},
{
value: "completed",
label: "Completed",
},
{
value: "deleted",
label: "Deleted",
},
{
value: "archived",
label: "Archived",
},
{
value: "archived_native_active",
label: "Archived Native Active",
},
{
value: "archived_native_completed",
label: "Archived Native Completed",
},
{
value: "archived_native_deleted",
label: "Archived Native Deleted",
},
];
24 changes: 24 additions & 0 deletions components/hubstaff/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
Loading